最新消息:20210917 已从crifan.com换到crifan.org

【已解决】小程序中调用服务器api接口出错:GET 400 (BAD REQUEST)

出错 crifan 699浏览 0评论
折腾:
【未解决】小程序中点击按钮调用服务器接口返回数据
期间,用代码:
代码:
    wx.request({
      url: queryUrl,
      success: function(response){
        console.log("response=%o", response)
      }
    })
报错:
Thu Nov 15 2018 17:35:41 GMT+0800 (CST) 配置中关闭合法域名、web-view(业务域名)、TLS 版本以及 HTTPS 证书检查
VM4538:1 工具未校验合法域名、web-view(业务域名)、TLS 版本以及 HTTPS 证书。
appservice?t=1542274537634:1117 GET http://xxx:33800/storybook?q=pig 400 (BAD REQUEST)

index.js? [sm]:49 response=Objectdata: {message: "The browser (or proxy) sent a request that this server could not understand."}errMsg: "request:ok"header: {Server: "gunicorn/19.9.0", Date: "Thu, 15 Nov 2018 09:35:41 GMT", Connection: "keep-alive", Content-Type: "application/json", Content-Length: "92", …}statusCode: 400__proto__: Object
而之前已经设置了绕开服务器域名和https的限制了:
小程序 GET 400 (BAD REQUEST)
微信小程序解决请求: 400 (Bad Request)错误 – qq_34501274的博客 – CSDN博客
微信小程序之请求400(Bad Request) – dingqk的博客 – CSDN博客
微信小程序wx.request报错400 bad request。按照示例编写的代码? – 问答 – 云+社区 – 腾讯云
新手请教问题 request 失败-小程序综合区-微信小程序开发社区-微信小程序联盟
微信小程序请求网络API 400错误的解决方法 – 程序园
加上:
header: {
      'content-type': 'application/json'
  },
错误依旧:
1. Object
    1. data:{message: "The browser (or proxy) sent a request that this server could not understand."}
    2. errMsg:"request:ok"
    3. header:{Server: "gunicorn/19.9.0", Date: "Thu, 15 Nov 2018 09:50:12 GMT", Connection: "keep-alive", Content-Type: "application/json", Content-Length: "92", …}
    4. statusCode:400
然后换成:
header: {
    
// 'content-type': 'application/json'
    
"Content-Type": "json"
},
竟然真的解决问题了,可以正常返回数据了:
换成:
微信小程序之请求400(Bad Request) – dingqk的博客 – CSDN博客
说的:
‘content-type’: ‘application/texts’
感觉或许是:
‘content-type’: ‘application/text’
结果:
也是可以的。
【总结】
微信小程序内部接口自己做的有问题:
发起请求 · 小程序
写的是:
“header
Object
设置请求的 header,header 中不能设置 Referer。
content-type 默认为 application/json”
结果没有传递:
header: {
    
'content-type': 'application/json'
},
则会报错400,倒是可以理解。
但是竟然改为:
header: {
    'content-type': 'application/text'
},
或:
header: {
    'content-type': 'json'
},
总之不是:
    ‘content-type’: ‘application/json’
就可以正常返回数据了。
-》其实不符合正常的逻辑:
本身GET的话,就无需操心content-type这个header才对。

转载请注明:在路上 » 【已解决】小程序中调用服务器api接口出错:GET 400 (BAD REQUEST)

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
93 queries in 0.383 seconds, using 23.44MB memory