获取javascript后无法获取响应正文

时间:2021-07-26 07:57:31

标签: javascript fetch httpresponse

我在尝试为 SMS Eagle 制作网络应用程序时遇到了这个烦人的问题。 我正在尝试向 SMS Eagle 服务器发送 API 请求,然后发送 SMS,这是成功的,但唯一的问题是我似乎无法获取响应正文。

在 Javascript 中,当我查看响应正文属性时,该值为“空”。但是当我查看网络选项卡时,我看到了值。请注意还有 'status: 0' 和其他看起来很奇怪的值。 Empty response body Non empty response body in network tab

我尝试使用 response.json()、response.text()、response.blob() 等获取值。我在这里做错了什么?我也已经尝试过多个内容类型的标题。这是我的代码:

fetch(`http://x.x.x.x/http_api/send_sms?login=${login_g}&pass=${pass_g}&message=${encodeURIComponent(message)}&to=${number}`, { method: 'GET', mode: 'no-cors', headers: { 'Content-Type': 'text/plain'}})
                    .then(response => response.text())
                    .then(data => console.log(data));

这些是来自服务器的响应头: Server response headers

亲切的问候, 碧玉

0 个答案:

没有答案
相关问题