使用Content-Type = application / x-www-form-urlencoded发送POST请求时,POST值为空

时间:2019-01-31 16:53:56

标签: php post postman

我已经通过邮递员发送了标有Content-Type = application / x-www-form-urlencode的POST请求。

我用以下格式在PHP中获得了$_POST数组。我无法在PHP页面中访问$_POST。我该如何解决?

<?php 
switch($method)
{
    case 'registration':
        print_r($_POST);exit;
    break;
}
?>

结果是

Array
    (
        [------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition:_form-data;_name] => "fname"

    bala
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition: form-data; name="lname"

    ba
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition: form-data; name="uname"

    stsbsathish
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition: form-data; name="address"

    chennai
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition: form-data; name="email"

    stsbsath2@gmail.com
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition: form-data; name="password"

    12345
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition: form-data; name="city"

    3
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition: form-data; name="state"

    7
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition: form-data; name="country"

    8
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition: form-data; name="phone"

    897973487
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo
    Content-Disposition: form-data; name="term"

    1
    ------WebKitFormBoundarydUQfNkeuyFTIFgMo--

    )

1 个答案:

答案 0 :(得分:0)

请注意,标头Content-Type应为:'application/x-www-form-urlencoded',而不要使用enctype="application/x-www-form-urlencoded"