0
$url3 = "http://cocatalog.loc.gov/cgi-bin/Pwebrecon.cgi?DB=local&PAGE=First";
$ch3 = curl_init();                   //2nd curl to search ASIN 
curl_setopt($ch3, CURLOPT_URL,$url3);
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch3, CURLOPT_TIMEOUT, 15);
curl_setopt($ch3, 156, 2500);
curl_setopt($ch3, CURLOPT_GETFIELDS,"?Search_Arg=$Kindletitle&Search_Code=TALL&CNT=25&HIST=1");
curl_setopt($ch3, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch3, CURLOPT_FOLLOWLOCATION, true);
$copyrightrecordresponse = curl_exec($ch3);
curl_close($ch3);

尝试对以下搜索表单执行 GET 请求,但我收到错误 curl_setopt() 期望参数 2 很长,给定字符串,

4

2 回答 2

0

也许我遗漏了一些东西,但你为什么不事先形成请求 URL?不完全确定您要完成什么,但看看这是否适合您:

$title='teste';

$url3="http://cocatalog.loc.gov/cgi-bin/Pwebrecon.cgi?Search_Arg=$title&Search_Code=TALL&CNT=25&HIST=1";

$ch3 = curl_init();                   //2nd curl to search ASIN 
curl_setopt($ch3, CURLOPT_URL,$url3);
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch3, CURLOPT_TIMEOUT, 15);
curl_setopt($ch3, 156, 2500);

curl_setopt($ch3,CURLOPT_HTTPGET,true);
curl_setopt($ch3, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch3, CURLOPT_FOLLOWLOCATION, true);
$copy= curl_exec($ch3);
curl_close($ch3);

echo($copy);

这将返回存储在 $title 变量中的字符串的搜索结果。

请参阅有关 curl 选项的文档中的此参考链接:

http://pt1.php.net/manual/en/function.curl-setopt.php

希望它有所帮助。:-)

于 2013-05-06T04:34:37.603 回答
0

首先cURL中没有 CURLOPT_GETFIELDS 。

第二。$Kindletitle 可能包含 URL 分隔符。所以,避免这样的事情:
"?Search_Arg=$Kindletitle&Search_Code=TALL&CNT=25&HIST=1"

使用urlencode ()。
但我会使用 array() 和http_build_query ():

$data = array(
    'Search_Arg'  => $Kindletitle,
    'Search_Code' => 'TALL',
    'CNT'         => 25,
    'HIST'        => '1'
);    
$query = http_build_query($data);

使用GET

$url = 'http://example.com?'.$query;
curl_setopt($ch3, CURLOPT_URL, $url);

或使用POST

curl_setopt($ch3, CURLOPT_POST, true );
curl_setopt($ch3, CURLOPT_POSTFIELDS, $query );

注意curl_setopt($ch3, 156, 2500);156。对于 Windows 平台
,它是相等的。CURLOPT_CONNECTTIMEOUT_MS由于某种原因,CURLOPT_CONNECTTIMEOUT_MS在某些 PHP 版本中定义不正确。可能不是你的情况,使用CURLOPT_CONNECTTIMEOUT_MS而不是156清楚。

于 2013-05-06T08:37:28.100 回答