📌  相关文章
📜  如何发送 post 请求 js fetch - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:30.985000             🧑  作者: Mango

代码示例1
componentDidMount() {
    // Simple POST request with a JSON body using fetch
    const requestOptions = {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ title: 'React POST Request Example' })
    };
    fetch('https://jsonplaceholder.typicode.com/posts', requestOptions)
        .then(response => response.json())
        .then(data => this.setState({ postId: data.id }));
}