首页 > 解决方案 > 发送带有空表单数据字段的 POST 请求

问题描述

问题是当我想发送一个带有空表单数据字段的 POST 请求时,我没有从服务器得到正确的响应。我通过 POSTMAN 提出了这个请求,它工作正常。我需要发送空和非空表单数据字段的混合,如下所示:

email_add_text:
email_add_text2:
email_address:
email_address2:xxxx
email_count:20
email_count2:20

我测试了https://github.com/guzzle/guzzle/issues/973中提到的解决方案;但是,无论是空字符串还是空值,都不能在 guzzle 中工作。如何使用 guzzle 或 php 中的任何其他工具来做到这一点?

标签: phpguzzle

解决方案


After some investigation, I checked the query with the Postman's Console. The trick is that we should embrace all of keys and values into the single or double quotations. Thus, the form-data fields on the guzzle should be like this:

'form_params' =>
    [
        'email_add_text' => "",
        'email_add_text2' => "",
        'email_address' => "",
        'email_address2' => "xxxx",
        'email_count' => "20",
        'email_count2' => "20"
    ]

推荐阅读