使用curl php设置http标头

时间:2014-10-10 10:38:19

标签: php curl

我已经使用自定义标头选项和一些帖子值发出了一个curl请求,但是当我执行我的代码时,由于连接被重置,我收到错误。

$data = array("StateCode" => "XX", "MemberMobileNo" => "XXXXXXXXXX" , "MemberMobilePin" => "XXXX");
$data = json_encode($data); 


$crl = curl_init(url);
$headr = array();
$headr[] = 'Content-type:application/json';
$headr[] = 'Content-length:115';
$headr[] = 'X-Username:XXXX';
$headr[] = 'X-Password:XXXXXXXX';
//print_r($headr);
curl_setopt($crl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($crl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($crl, CURLOPT_VERBOSE, TRUE);
curl_setopt($crl, CURLOPT_HEADER, true);
curl_setopt($crl, CURLOPT_HTTPHEADER,$headr);
curl_setopt($crl, CURLOPT_POST,true);
curl_setopt($crl, CURLOPT_POSTFIELDS, $data);
curl_setopt($crl, CURLOPT_RETURNTRANSFER,true);
$rest = curl_exec($crl);

if ($rest === false)
{
    print_r('Curl error: ' . curl_error($crl));
}

curl_close($crl);
print_r($rest);

错误=>卷曲错误:Recv失败:连接已重置

0 个答案:

没有答案