如何在chrome开发工具中查看帖子正文数据?

时间:2018-12-16 02:12:17

标签: php reactjs google-chrome fetch

我在React中有这个访存api,它正在向服务器发送数据。服务器运行PHP,我无法通过$ _POST或file_get_contents('php:// input');

访问数据

因此,我想检查过程的每个步骤,直到看到错误在哪里。我还想验证发布数据的发送方式。即我想查看实际数据和来自浏览器的完整请求。

获取请求如下:

export function sendEmail (data) {
  return fetch('http://example.com/email.php', {
    method: 'POST',
    credentials: 'same-origin',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
  }).then(response => response.json())
}

当我进入google chrome的开发工具时,我看到了请求标头,响应等,但是我什么也看不到实际发送的数据。我在网上四处张望,似乎没人能给出明确的答案。

3 个答案:

答案 0 :(得分:1)

Fiddler在这种情况下可能会有所帮助。它将向您显示发送到您的PHP端点的帖子正文。

答案 1 :(得分:1)

在开发工具中,单击“网络”选项卡,然后执行请求并单击它。滚动到“请求正文”部分。 Network tab

答案 2 :(得分:1)

我建议您使用axios,它更容易检查是成功还是错误,并且更干净:

没有任何正文发送的帖子;

mockFile.url

带有一些参数:

import axios from 'axios';

axios.post('http://example.com/email.php')
.then(response=>response.data)
.then(response=>console.log('Success:', response))
.catch(err=>console.log('Error: ',err))