如何使用 POST 请求(本机反应)将字符串发送到 Web 服务?
How can I send a String to a web service using POST request (react native)?
是否可以使用 POST 请求(本机响应)将字符串发送到 PHP 网络服务?我只找到一些 JSON POST 请求,如下所示:
functionName = async() => {
const response = await fetch('http://localhost/webservice.php', {
method: 'POST',
mode: 'no-corse',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
searchQuery: 'something',
})
})
const myData = await response.json();
this.setState({data: myData});
}
如何将其转换为发送一个字符串(就像一个单词)而不是 JSON 字符串?
类似
functionName = async() => {
const response = await fetch('http://localhost/webservice.php', {
method: 'POST',
mode: 'no-corse',
headers: {
Accept: 'application/json',
'Content-Type': 'text/plain'
},
body: 'Your text'
})
const myData = await response.json();
this.setState({data: myData});
}
是否可以使用 POST 请求(本机响应)将字符串发送到 PHP 网络服务?我只找到一些 JSON POST 请求,如下所示:
functionName = async() => {
const response = await fetch('http://localhost/webservice.php', {
method: 'POST',
mode: 'no-corse',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
searchQuery: 'something',
})
})
const myData = await response.json();
this.setState({data: myData});
}
如何将其转换为发送一个字符串(就像一个单词)而不是 JSON 字符串?
类似
functionName = async() => {
const response = await fetch('http://localhost/webservice.php', {
method: 'POST',
mode: 'no-corse',
headers: {
Accept: 'application/json',
'Content-Type': 'text/plain'
},
body: 'Your text'
})
const myData = await response.json();
this.setState({data: myData});
}