AJAX POST请求在POSTMAN中工作但在Chrome中没有 [英] AJAX POST request working in POSTMAN but not in Chrome

查看:479
本文介绍了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)时,它会从服务器返回。仔细检查您在代码中传递给post请求的数据类型。

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不支持的媒体类型原始服务器拒绝为请求提供
服务,因为有效负载的格式不受此支持目标资源上的
方法。

415 UNSUPPORTED MEDIA TYPE The origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource.

格式问题可能是由于请求指示
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中没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆