我正在使用asmx
网络服务。但是我不知道如何发送请求。
我的网络服务:
http://188.75.80.115:83/WebService1.asmx?op=getKey
我可以使用fetch
吗?
另一个问题是回应。该Web服务的响应是:
<databack xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">
<Status>true</Status>
<Error/>
<Data>4yhj6mXwKTkkz4MJjaNfS/BRK8cx6/gH</Data>
</databack>
我认为我应该使用react-native-xml2js
。正确吗?
答案 0 :(得分:0)
如果使用Javascript,则可以使用以下代码将请求发送到Webservice。
$.ajax({
type: "POST",
url: "Ajax.asmx/{your-service-function}",
data: JSON.stringify({ firstParam: 'value'}),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
或者,如果您使用的是React,请使用以下代码
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
firstParam: 'yourValue',
secondParam: 'yourOtherValue'
})
}).then((response) => response.json()).then((responseJson) => {
// response in responseJson
}).catch((error) => {
//handle your error
});
此链接还将帮助您Fetch