为auth FAILED发送自定义标头,而不是在web api中请求

时间:2015-06-09 01:01:33

标签: php json curl

我发送了一个自定义标题,如下所示:

//HTTP HEADERS
$date = gmdate("M, d Y H:i:s \G\M\T", time());
$contentType = "Content-Type: application/json; charset=UTF-8";
$xIncommDateTime = substr(substr_replace(date('c'), substr(round(microtime(), 3), 1, 8), 19, 0), 0, -6) . "Z";
$acceptLanguage = "Accept-Language: en-US, en";

$header = array("Date: ".$date, $contentType, $accept, "X-Incomm-DateTime: ".$xIncommDateTime, "Authorization: ".$authorization);

并在CURL php中发帖:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header . strlen($request));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

$result = curl_exec($ch);

我的问题是内容类型....发送邮件后会发生变化,如下所示:[content_type] => text/html;charset=UTF-8,显示在:

$info = curl_getinfo($ch);
echo "<pre>";
print_r($info);
echo "</pre>";

这是错误的,并在我的代码中出现内部错误.....写入标题和自定义类型显示内容类型...结果是两个内容类型并在我的请求中混淆!! !!

  [request_header] => POST /v1/requestActiveCode HTTP/1.1
Host: IP.A.D.R.E.S.S
Date: Jun, 08 2015 22:02:13 GMT
Content-Type: application/json; charset=UTF-8

我如何更改代码中发送的内容类型为正确的类型,并最终从我的webservice API获得结果?提前谢谢

0 个答案:

没有答案