错误OPTIONS net :: ERR_CONNECTION_REFUSED [英] Error OPTIONS net::ERR_CONNECTION_REFUSED
问题描述
我正在使用"jQuery"(前端)和"Python"(后端)开发Web应用程序.发出PUT请求以更新数据库中的详细信息时,这是我在控制台中看到的错误:
I am developing a web application using "jQuery"(front-end) and "Python"(back-end). While making a PUT request to update details in the database, this is the error I get in the console:
OPTIONS"REST API URL" net :: ERR_CONNECTION_REFUSED
OPTIONS "REST API URL" net::ERR_CONNECTION_REFUSED
我的jQuery代码是:
My jQuery code is:
$.ajax({
type: "PUT",
url: "REST API URL",
headers: {"Content-Type": "application/json", "Authorization": AuthToken},
data: "details to be updated in database",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data,status) {
//do something with data
},
error: function(data,status) {
//show error data and status
}
)};
我了解了除GET
和POST
之外的其他HTTP请求如何首先作为OPTIONS请求预处理,并且只有当它是真正的请求时,才作为PUT/DELETE/PATCH
请求进行处理.
我看到的解决方案说它可能是CORS
问题,但是从后端启用启用了CORS
来允许GET/POST/PUT/PATCH/DELETE
请求.此外,我能够成功发出GET
和POST
请求,但没有任何PUT
请求正在处理.
我正在使用"Chrome开发工具",并研究了如何通过清除缓存和cookie,刷新DNS并重新安装Chrome来解决Chrome的此错误,但到目前为止,这些解决方案都无法正常工作.
我正在制作前端UI,不确定是客户端错误还是服务器端错误?
任何帮助将不胜感激.
I read about how HTTP Requests other than GET
and POST
are first pre-flighted as OPTIONS request and only when it is a genuine request, it gets processed as a PUT/DELETE/PATCH
request.
I saw solutions where it said that it might be a CORS
issue, but CORS
is enabled from the back-end to allow GET/POST/PUT/PATCH/DELETE
requests. Further, I am successfully able to make GET
and POST
requests but no PUT
requests are going through.
I am using "Chrome Dev Tools" and researched about how to fix this error for Chrome by clearing cache and cookies, flushing DNS and re-installing Chrome but none of the solutions have worked so far.
I am a making the front end UI and am not sure whether this is a client-side error or a server-side error?
Any help would be appreciated.
推荐答案
可以肯定的是,这是一个后端问题.当后端和前端之间的跨源通信未正确连接时,会发生这种情况.考虑到您已经导入了cors并设置了中间件,很可能在源URL和请求URL方面使用PUT方法都犯了一个错误.
One thing is for sure, this is a backend problem. This happens when the cross origin communication between the backend and frontend is not connected properly. Considering you have imported cors and set up the middleware, most probably you have made a mistake using the PUT method in terms of the origin URL and request URL.
您可以做的事情:
1)确保两个服务器(后端和前端)都在运行.
1) Make sure both servers are running (the back-end and front end).
2)查看Google开发工具并查看网络部分.查看请求标头和常规标头.确保请求URL/后端具有您的后端服务器URL,并且 orgin/frontend 具有您的前端URL.
2) Look into google development tool and see the network section. Look at the request headers and the general. Make sure the request URL / backend has your backend server URL and the orgin / frontend has your frontend URL.
3)确保在您的http.put()方法中,要为其喂入的域与您在服务器中设置的api匹配.
3) Make sure in your http.put() method, the domain you are feeding it matches the api you set up in your server.
4)您的问题是后端未正确连接到前端,因此请不要浪费时间尝试查找其他错误.专注于调试http.put()方法以及已导入的cors模块和中间件.
4) Your issue is that your backend is not connected with your front end properly,so don't waste your time trying to find other errors. Focus on debuging the http.put() method and the cors module and middleware you have imported.
这篇关于错误OPTIONS net :: ERR_CONNECTION_REFUSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!