【问题标题】:Unsupported Media Type" message: "Content type '' - but works in POSTMAN不支持的媒体类型”消息:“内容类型 '' - 但在 POSTMAN 中有效
【发布时间】:2021-04-19 21:00:24
【问题描述】:

当我尝试在 ReactJS 中调用此 GET 方法时,我遇到了问题。错误=“不支持的媒体类型”。但是当我在 POSTMAN 中调用方法时,它适用于 Content-type: application/json。

const API_URL="http://****/sample/";
class Service{    
getKnjige(){
    const token = getToken();

    return axios.get(API_URL,{    

        headers:{'Content-Type': 'text/xml',
        dataType: "json",} 
    })
    
}

错误:

{时间戳:“2021-01-14T19:22:39.096+0000”,状态:415,错误:“不支持的媒体类型”,...} 错误:“不支持的媒体类型” 消息:“不支持内容类型” 路径:“/样本/” 状态:415 时间戳:“2021-01-14T19:22:39.096+0000”

【问题讨论】:

    标签: reactjs content-type http-status-code-415


    【解决方案1】:

    您正在发出 GET 请求。

    根本没有请求正文,更不用说 XML 请求正文了。

    如果您不发送内容,请勿在您的请求中设置 Content-Type。


    HTTP 中根本没有 dataType 请求(或响应)标头。

    dataType 是 jQuery 的一个配置选项……你没有使用它。

    【讨论】:

      猜你喜欢
      • 2017-12-02
      • 2019-03-23
      • 2021-05-20
      • 2020-09-19
      • 2020-06-02
      • 2018-10-13
      • 2019-02-25
      • 1970-01-01
      • 2017-08-17
      相关资源
      最近更新 更多