解决PHP获取不了 React Native Fecth参数的问题
React Native 使用 fetch 进行网络请求,推荐Promise的形式进行数据处理。官方的 Demo 如下: fetch('https://mywebsite.com/endpoint/', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ username: 'yourValue', pass: 'yourOtherValue', }) }).then((response) => response.json()) .then((res) => { console.log(res); }) .catch((error) => { console.warn(error); }); 但是实际在进行开发的时候,却发现了php打印出 $_POST为空数组。这个时候自己去搜索了下,提出了两种解决方案: 构建表单数据 function toQueryString( 详情 »