本文介绍了AJAX POST 请求在 POSTMAN 中有效,但在 Chrome 中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发出一个简单的 AJAX POST 请求.在 POSTMAN 中执行此请求时工作正常.但是,当我在 jQuery 中对其进行编码并尝试发出相同的请求时,我得到了

I am trying to make a simple AJAX POST request. This request when executed in POSTMAN works fine. However, when I code it in jQuery and try to make the same request, I get

请求的资源上不存在Access-Control-Allow-Origin"标头.因此,Origin 'file://' 不允许访问.响应的 HTTP 状态代码为 415.

现在,我必须发出一个 POST 请求,因此在请求中使用 JSONP 作为类型将无济于事.我无权访问服务器代码来修改它.我的基本理解是,如果POSTMAN可以执行,那么我应该也可以执行

Now, I have to make a POST request and hence using JSONP as type in the request won't help. I do not have access to server code to modify it. My basic understanding is that if POSTMAN can execute it, then i should be able to do it as well

推荐答案

状态码一目了然.415 当您发送不受支持的内容类型(例如 xml)时,它会从服务器返回.仔细检查您在代码中传递给发布请求的数据类型.

the status code is self explanatory.415 it's returned from the server when you sent an unsupported content type (e.g. an xml). double check the type of data you're passing to the post request in your code.

415 UNSUPPORTED MEDIA TYPE 源服务器拒绝服务请求,因为有效负载的格式不受此支持目标资源上的方法.

格式问题可能是由于请求的指示Content-Type 或 Content-Encoding,或作为检查的结果直接数据.

The format problem might be due to the request's indicated Content-Type or Content-Encoding, or as a result of inspecting the data directly.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415

这篇关于AJAX POST 请求在 POSTMAN 中有效,但在 Chrome 中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 06:16