【发布时间】:2018-07-19 18:40:00
【问题描述】:
尝试调试一个新的 React-native 应用程序 - 非常大而且它没有后端,所以我正在尝试存根一些东西。
请求格式对我来说很陌生。有谁认识这种格式或知道如何处理它?
proc_name=customer_ref¶ms={"fields" : ["customerId"],"conditions":[{"mailAddress":"dsadsa"},{"pinCode":"ZHNhZHNh"},{"mailReceiveFlag":"1"}],"order" : ["customerCode desc"],"limit" : "1","table_name" : "Customer"}
React-native 请求代码如下所示:
try{
let result = await fetch(apiUrl, {
method: 'POST',
headers: {
'X_contract_id': contact_id,
'X_access_token': access_token,
'Content-Type': 'application/x-www-form-urlencoded',
'charset':'UTF-8',
},
body: 'proc_name='+proc_name+'¶ms={'+params+'}'
}).then((response) => response.json())
.then((responseJson) => {
return responseJson.result;
})
return result;
}catch(e){
console.log(e);
}
应用程序在到达我启动的服务器之前就出现了未处理的 Promise Rejection 错误。这里很新;我在前端层做错了吗?
【问题讨论】:
-
参数看起来更像一个 JSON 字符串。如果 Content 类型是 application/json,我会推荐 JSON.stringify(params)。
标签: http react-native