如何在cURL中发布带有无线电按钮的表格?

时间:2018-04-20 09:15:04

标签: php curl post

服务器站点中的表单包含一个文本框和两个单选按钮以及一个提交按钮。这是我尝试过的。请帮忙。

enter image description here

        $url = "Url goes here";

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"postcode\":\"3150\", \"customerType\":\"Residential\",\"fuelType\":\"Electricity\"}");
        curl_setopt($ch, CURLOPT_POST, 1);

        $headers = array();
        $headers[] = "Content-Type: application/x-www-form-urlencoded";
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
            echo "test";
        }

        echo "<pre>";
        print_r($result);
        echo "</pre>";

        curl_close($ch);
    }

    ?>

1 个答案:

答案 0 :(得分:1)

它的工作方式与文本值相似。

找到这些收音机的名称,检查您想要的值。

示例:

<form>
    <input type="radio" name="gender" value="male" checked> Male<br>
    <input type="radio" name="gender" value="female"> Female<br>
    <input type="radio" name="gender" value="other"> Other  
</form>

您的cURL Postfield应如下所示:

$data = array('gender' => 'male');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);