Php 使用cUrl提交表单
我想用Php 使用cUrl提交表单,php,curl,Php,Curl,我想用cUrl向提交任何IP地址。我的卷曲选项无法正常工作: $h = curl_init(); curl_setopt($h, CURLOPT_URL, "http://www.whatismyip.com/ip-whois-lookup/"); curl_setopt($h, CURLOPT_POST, true); curl_setopt($h, CURLOPT_POSTFIELDS, array( 'IP' => '2.179.144.117', 'su
cUrl
向提交任何IP地址。我的卷曲选项无法正常工作:
$h = curl_init();
curl_setopt($h, CURLOPT_URL, "http://www.whatismyip.com/ip-whois-lookup/");
curl_setopt($h, CURLOPT_POST, true);
curl_setopt($h, CURLOPT_POSTFIELDS, array(
'IP' => '2.179.144.117',
'submitted' => 'submitted'
));
curl_setopt($h, CURLOPT_HEADER, false);
curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($h);
echo $result;
快速检查发送到该网页的标题,就会发现“submitted”post变量应该设置为true,而不是submitted
备注:请注意whatismyip.com可能不允许通过刮取方式访问其工具 使用
http\u build\u query()
函数提供数组数据,以便在请求的IP上正确解码:
curl_setopt($h, CURLOPT_POSTFIELDS, http_build_query(
array(
'IP' => '2.179.144.117',
'submitted' => 'submitted'
)
));
// echo http_build_query(array('IP' => '2.179.144.117', 'submitted' => 'submitted'));
// outputs: IP=2.179.144.117&submitted=submitted and this will be added to the end of
// the requested URL in GET request.
正如user3280126所述,您应该将post数据作为“IP=2.179.144.117&submitted=true”传递。我一定看过了,谢谢。出现此错误的原因:
403禁止
。whatismyip.com
的服务器不允许访问cUrl?我不知道如何使用whatismyip.com
服务,但403表示无论使用cUrl,该服务都不允许您的IP。