温馨提示:本文翻译自stackoverflow.com,查看原文请点击:react native android - How to fetch Webservice which takes string parameter?
react-native-android

react native android - 如何获取带有字符串参数的Webservice?

发布于 2020-03-27 11:02:37

我尝试获取webservice方法。但是,它需要字符串。如何将字符串参数发送到webservice?

我这样尝试过:

 fetch('url/MethodName', {
        method: 'POST',
        headers: new Headers({
                      Accept: 'application/json',
                    'Content-Type': 'application/json', 
            }),
        })

我应该在哪里放置字符串参数?

查看更多

查看更多

提问者
hakan
被浏览
25
Bob White 2019-07-03 22:27

由mozilla

var url = 'https://example.com/profile';
var data = {username: 'example'};

fetch(url, {
  method: 'POST', // or 'PUT'
  body: JSON.stringify(data), // data can be `string` or {object}!
  headers:{
    'Content-Type': 'application/json'
  }
}).then(res => res.json())
.then(response => console.log('Success:', JSON.stringify(response)))
.catch(error => console.error('Error:', error));

发送Json数据作为参数