简体   繁体   English

在 axios 请求 Javascript 中从 Content-type/html 转换为 Json

[英]Converting from Content-type/html to Json in axios request Javascript

I am getting response from API using axios in Javascript. However, the problem i am facing is that response is coming as content-type: text/html;我正在使用 Javascript 中的 axios 从 API 获得响应。但是,我面临的问题是响应以内容类型出现:文本/html; charset=UTF-8, I cannot parse the response since it is not JSON. Has anyone faced this problem earlier, i will say thank you if you guys help, Thank you so much. charset=UTF-8,我无法解析响应,因为它不是 JSON。有没有人早些时候遇到过这个问题,如果你们帮忙,我会说谢谢,非常感谢。

You can set Accept: application/json in your request headers.您可以在请求标头中设置Accept: application/json Something like就像是

axios.get(url, {
    headers: {
        Accept: 'application/json'
    }
}

It also depends on your back-end.这也取决于您的后端。 If your back-end doesn't support JSON response, you can't get JSON.如果你的后端不支持 JSON 响应,你将无法获得 JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM