我在PHP中使用YQL與file_get_contents發送查詢。我使用YQL進行術語提取,所以我的查詢包含大量文本。不幸的是,這會導致URL過長,並返回錯誤。如果我使用更少量的文本,它工作正常。PHP/YQL/GET:URL太長
是唯一可以在YQL上使用SELECT語句和GET的唯一方法,除了使用少量文本之外,還有哪些其他選項?
我在PHP中使用YQL與file_get_contents發送查詢。我使用YQL進行術語提取,所以我的查詢包含大量文本。不幸的是,這會導致URL過長,並返回錯誤。如果我使用更少量的文本,它工作正常。PHP/YQL/GET:URL太長
是唯一可以在YQL上使用SELECT語句和GET的唯一方法,除了使用少量文本之外,還有哪些其他選項?
是我能在YQL使用SELECT語句得到的唯一途徑,做什麼其他的選擇我除了使用文字的更少?
正如其他人所說的,您可以使用POST請求而不是GET。以下是使用file_get_contents()
和流上下文的示例。 cURL或任何其他可以發出POST請求的遠程內容獲取代碼也可以正常工作。
$ctx = stream_context_create(array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => http_build_query(array(
'context' => $my_really_really_huge_context,
'query' => $query,
'format' => 'json',
'q' => 'SELECT * FROM search.termextract WHERE [email protected] and [email protected]'
))
)));
$json = file_get_contents('http://query.yahooapis.com/v1/public/yql', false, $ctx);
爲什麼不使用CURL而不是使用get變量查詢?
$c = curl_init("http:/query.yahooapis.com/v1/public/yql?q=myverylongquery&format=json");
curl_setopt($c, CURLOPT_RETURNTRANSFERT, 1); // returns the data into the variable
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 20); // query times out after 20 seconds
$data = json_decode(curl_exec($c)); // I asked for data format to be in json in the query
curl_close($c);
嘗試使用捲曲和帖子? file_get_contents與流? – ajreal 2011-01-10 07:31:48