我正在使用以下代码从API检索数据:
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=> "Cookie: JSESSIONID=CF0D1FA323B4F3FCEF90BA3EE4651CAC\r\n"
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents('http://webfeeder.cedrofinances.com.br/services/quotes/quote/vale5', false, $context);
上面的代码返回以下错误消息:
警告:file_get_contents(http://webfeeder.cedrofinances.com.br/services/quotes/quote/vale5):无法打开流:HTTP请求失败!
中不允许使用HTTP / 1.1 405方法API使用REST(HTTP)。上述方法在文档中描述为GET。 我也尝试过使用PHP CURL。但是会显示相同的错误消息。
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "http://webfeeder.cedrofinances.com.br/services/quotes/quote/vale5",
CURLOPT_HTTPHEADER => array("Cookie: JSESSIONID=CF0D1FA323B4F3FCEF90BA3EE4651CAC"),
));
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
API文档显示了以下用于检索此相同数据的JAVA代码:
public void getQuote(){
GetMethod getMethod = new GetMethod ("http://webfeeder.cedrofinances.com.br/services/quotes/quote/vale5");
String result = HttpUtils.get(getMethod);
System.out.println(resutl);
}