简体   繁体   English

如何发送像表单数据邮递员这样的值-React JS

[英]How to send values like form-data postman - react js

I'm using fetch to send value to my server. 我正在使用fetch将价值发送到我的服务器。 my server is php. 我的服务器是php。 when I send my values with postman my server response as well. 当我用邮递员发送值时,我的服务器响应也是如此。

but when I want to send my values with fetch I cannot get them from server side. 但是当我想通过获取发送值时,无法从服务器端获取它们。

postman: 邮差: 在此处输入图片说明

my requestOption: 我的requestOption:

  const requestOptions = {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },

            body: JSON.stringify(parms)
        };

my values sent to server but I cannot get them like postman form-data. 我的值已发送到服务器,但无法像邮递员表格数据那样获取它们。

parms is a object variable. parms是一个对象变量。 like: 喜欢:

var parms = {};
parms['tok'] = '35345345';

Just use formData as fetch body: 只需使用formData作为fetch主体:

var formData = new FormData()
formData.append("tok", '35345345')
const requestOptions = {
        method: 'POST',
        headers: {
            'Accept': 'application/json'
        },

        body: formData
    };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM