3

我正在尝试将图像的字节数组发送到我的 json 对象中的 web 服务。但是,它的请求永远不会到达我的服务器。如果我只发送一个空数组,它会到达服务器并返回 json 响应。下面是我的代码。这段代码有什么问题

<?php 


header('Content-type: application/json');
//Read an image from third party URL
$contents= file_get_contents('http://i2.cdn.turner.com/cnn/dam/assets/120612031415-granderson-speech-c1-main.jpg');
$byteArr = str_split($contents);
foreach ($byteArr as $val) 
{ 
 $points[] = ord($val); 
}
$output = join (" " , $points);
//echo($output);
//If i use "photo"=>[] in below array it works fine
$jsonArray = array("comments"=>"Hiee", "type"=>"test", "photo"=>[$output],"custid"=>"test@test.com");
$buzz = json_encode($jsonArray);
try {
//Webservice call to store the image in DB and send mail
$jsonResponse = @file_get_contents("http://localhost/example/json.htm?action=sendBuzzRequest&email=test@test.com&pass=test1234&buzz=".$buzz);
echo ($jsonResponse);
} catch(Exception $e)
{
 $e->getMessage();
}
?>

非常感激你的帮助。

4

2 回答 2

2

如果这解决了它,我不支持,但 url 没有编码。你可以先试试。

$jsonResponse = @file_get_contents("http://localhost/example/json.htm?action=sendBuzzRequest&email=test%40test.com&pass=test1234&buzz=" . urlencode($buzz));
于 2012-06-14T11:53:22.097 回答
1

根据评论,似乎您可能已达到 GET 请求的最大大小..

这种规范看起来更适合 POST 或 PUT 请求。

有关 GET 大小请求限制,请参阅此 SO 问题:HTTP GET 请求的最大长度?

于 2012-06-14T23:35:28.650 回答