我整天都在用以下方法扯头发:
我正在尝试使用此博客文章中的 PHP 移植代码向 Google Goggles 发送手动请求:http: //notanothercodeblog.blogspot.com/2011/02/google-goggles-api.html
原始博客文章显然是用 .NET 编写的工作代码,但我的平台是 PHP。我的代码是:
$googleID = substr(md5(rand()), 0, 16);
/* */
$url = 'http://www.google.com/goggles/container_proto?cssid=' . $googleID;
// $url = 'http://www.google.com/goggles/container_proto?cssid=';
// $googleCodes = array(0x22,0x00,0x62,0x3C,0x0A,0x13,0x22,0x02,0x65,0x6E,0xBA,0xD3,0xF0,0x3B,0x0A,0x08,0x01,0x10,0x01,0x28,0x01,0x30,0x00,0x38,0x01,0x12,0x1D,0x0A,0x09,0x69,0x50,0x68,0x6F,0x6E,0x65,0x20,0x4F,0x53,0x12,0x03,0x34,0x2E,0x31,0x1A,0x00,0x22,0x09,0x69,0x50,0x68,0x6F,0x6E,0x65,0x33,0x47,0x53,0x1A,0x02,0x08,0x02,0x22,0x02,0x08,0x01);
$googleCodes = array(34,0,98,60,10,19,34,2,101,110,186,211,240,59,10,8,1,16,1,40,1,48,0,56,1,18,29,10,9,105,80,104,111,110,101,32,79,83,18,3,52,46,49,26,0,34,9,105,80,104,111,110,101,51,71,83,26,2,8,2,34,2,8,1);
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, array("CssidPostBody" => implode("",$googleCodes)));
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/x-protobuffer",
"Pragma: no-cache"));
$response = curl_exec($handle);
/* */
print_r($response);
我不断收到来自 Google 的以下回复:
"Unparseable Container Request"
我相信我的问题是$googleCodes
. 原始文章有以下内容:
private static byte[] CssidPostBody = new byte[] { 34, 0, 98, 60, 10, 19, 34,
2, 101, 110, 186, 211, 240, 59, 10, 8, 1, 16, 1, 40, 1, 48, 0, 56, 1, 18,
29, 10, 9, 105, 80, 104, 111, 110, 101, 32, 79, 83, 18, 3, 52, 46, 49,
26, 0, 34, 9, 105, 80, 104, 111, 110, 101, 51, 71, 83, 26, 2, 8, 2, 34,
2, 8, 1 };
我意识到这是一个可能非常独特的问题,但我希望有 .NET 字节数组经验的人可以为我指明正确的方向。