HarmonyOS RCP数据请求post一个from表单如何实现?

如题:HarmonyOS RCP数据请求post一个from表单如何实现?

阅读 541
1 个回答

参考官方文档

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/remote-communication-rcp-V5\#section1188301010515

let headers: rcp.RequestHeaders = {
  "accept": "application/json"
};
let configuration: rcp.Configuration = {
  transfer: {
    timeout: { connectMs: 60000, transferMs: 60000 }
  }
};
let cookies: rcp.RequestCookies = { 'name1': 'value1', 'name2': 'value2' };
let transferRange: rcp.TransferRange = { from: 100, to: 200 };

const simpleForm = new rcp.Form({
  "key1": "value1",
  "key2": ["valueList0", "valueList1"],
})

let req = new rcp.Request("http://example.com", "POST", headers, simpleForm, cookies, transferRange, configuration);
req.content = simpleForm;