从PHP到。net (Win Server)的API,使用cURL
我的最后一部分代码是:
$response = curl_exec($ch);
$responseArray = json_decode($response, true);
当我这样做的时候:
print_r($response);
进入浏览器:
HTTP/1.1 201 Created Cache-Control: no-cache Pragma: no-cache Content-Length: 64 Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/8.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Wed, 05 Aug 2015 12:44:50 GMT {"resultCode":0,"resultMessage":"Success","order_number":123456}
当我这样做的时候:
print_r($responseArray);
屏幕空白
所以我的问题是我如何从这个响应中获取变量?
我会尝试设置curlopt不返回Output Headers。
PHP: curl_setopt
您要设置的项目是CURLOPT_HEADER
例子:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
此时,您的响应($response)应该是json编码的字符串。额外的好处是,如果你目前没有使用JSON输出期望,你可能还想强制执行该设置。
// Set The Response Format to Json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
更多信息在这里:PHP Curl,请求数据返回在application/json