HarmonyOS http 请求 post 参数问题

官方demo示例

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/http-request-V5

let httpRequest = http.createHttp();  
httpRequest.request(APIConst.Home_InfoFlow, {  
  method: http.RequestMethod.POST,  
  header: {  
    'Content-Type': 'application/x-www-form-urlencoded'  
  },  
  extraData: {  
    id: "123",  
    name: "4567",  
    value: "哈啊大声道",  
    pageNo: 1,  
    pageSize: 20,  
    flowClassId: 3  
  },  
  usingProxy: {  
    host: "http://196.3.2.233",  
    port: 8888,  
  } as http.HttpProxy  
}, (err: BusinessError, data: http.HttpResponse) => {  
  console.log("123", JSON.stringify(data))  
  console.log("543", err)  
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.

抓包入参格式是。

{"id":"123","name":"4567","value":"哈啊大声道","pageNo":1,"pageSize":20,"flowClassId":3} 
  • 1.

参入格式有误。

正常请求抓包格式应为:

id=123&name=4567&value=哈啊大声道&pageNo=1&pageSize=20&flowClassId=3
  • 1.

目前接口响应接受不到参数。

HarmonyOS
2024-10-21 11:48:58
3895浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

当'content-Type'为'application/x-www-form-urlencoded'时,请求提交的信息主体数据必须在key和value进行URL转码后(encodeURIComponent/encodeURI),按照键值对"key1=value1&key2=value2&key3=value3"的方式进行编码,该字段对应的类型通常为String。文档说明:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-http-V5#httprequestoptions

当前'Content-Type'设置为'application/x-www-form-urlencoded',需要手动设置extraData格式为key1=value1&key2=value2&key3=value3的方式,不会自动转换。

分享
微博
QQ
微信
回复
2024-10-21 16:51:18


相关问题
HarmonyOS http post请求参数传递
1143浏览 • 1回复 待解决
HarmonyOS HTTP-post请求接收不到参数
1066浏览 • 1回复 待解决
使用post请求无法带入extraData参数问题
1109浏览 • 1回复 待解决
关于JS http请求参数的传递问题
8440浏览 • 2回复 待解决
HTTP GET请求时如何传递参数
4178浏览 • 1回复 待解决
HarmonyOS http网络访问,参数问题
1070浏览 • 1回复 待解决
HarmonyOS Http请求问题咨询
1157浏览 • 1回复 待解决
HarmonyOS POST请求传参
1108浏览 • 1回复 待解决
http请求中能否不设置Content-Type参数
3044浏览 • 1回复 待解决
HarmonyOS http请求的JSON数据定义问题
1163浏览 • 1回复 待解决
HarmonyOS RCP GET请求POST请求如何传参
1078浏览 • 1回复 待解决
HarmonyOS RN项目下http请求头header问题
847浏览 • 1回复 待解决