+ -
当前位置:首页 → 问答吧 → 用curl函数POST之后怎么只获取header

用curl函数POST之后怎么只获取header

时间:2011-10-15

来源:互联网

PHP code

$url ='www.123.com';
$post = '$sgdsg=dsgdsg'
echo post($url,$post);
function post($url,$post){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
curl_setopt($ch,CURLOPT_USERAGENT,"Chrome/9.0.587.0");
$ex = curl_exec($ch);
curl_close($ch);
return $ex;
}



这个可以只获取HEADER 但是他不发送POST 也不以POST形式发送

我想要他 Post数据过去只获取HEADER不要内容


作者: wxinlin   发布时间: 2011-10-15

你确定你要提交的表单是post给www.123.com?
给你一个典型的例子看一下应该会清楚:
PHP code
        $ch = curl_init( );
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
        curl_setopt( $ch, CURLOPT_URL, "https://reg.163.com/logins.jsp" );
        curl_setopt( $ch, CURLOPT_POST, 1 );
        curl_setopt( $ch, CURLOPT_POSTFIELDS, "username=".$username."&password=".$password );
        curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie_jar );
        curl_setopt( $ch, CURLOPT_TIMEOUT, 15);
        ob_start( );
        curl_exec( $ch );
        $contents = ob_get_contents( );

作者: hellodifa   发布时间: 2011-10-15

引用 1 楼 hellodifa 的回复:

你确定你要提交的表单是post给www.123.com?
给你一个典型的例子看一下应该会清楚:
PHP code
$ch = curl_init( );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_URL, "https://reg.……

这个好像不能只获取Header吧? 我不需要body 只需要Header

作者: wxinlin   发布时间: 2011-10-15

$post = '$sgdsg=dsgdsg';
这个是你要post的数据么?为啥会有个$在里边?
sgdsg是要传递的变量名么?

作者: ohmygirl   发布时间: 2011-10-15