【发布时间】:2013-06-30 04:39:39
【问题描述】:
我正在尝试从通常以XML 返回的服务器检索数据,但我尝试以 JSON 格式请求它(如果请求正确,它将以 JSON 返回数据)。
$header = array(
'http' => array(
'header'=>"Content-type: application/json"
),
);
$response = file_get_contents($query, false, $header);
print_r($response);
这种方法取自here。目前该程序不返回任何内容。 有人发现这有什么潜在的问题吗?
【问题讨论】:
-
管理您请求的服务器或应用程序的人应该能够告诉您如何正确地为该特定服务器或应用程序请求 JSON。
-
@SajanParikh:HTTP 标准还告诉您如何操作。 w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
-
@SLaks 当然,但是您请求的应用程序或服务器必须遵守这一点。
标签: php http file-get-contents