我正在尝试将图像的字节数组发送到json object中的webservice.But,请求永远不会到达我的服务器。如果我只发送一个空数组,它会命中服务器并返回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();
}
?>
非常感谢您的帮助。
答案 0 :(得分:2)
$jsonResponse = @file_get_contents("http://localhost/example/json.htm?action=sendBuzzRequest&email=test%40test.com&pass=test1234&buzz=" . urlencode($buzz));
答案 1 :(得分:1)
根据评论,您似乎可能已达到GET请求的最大大小。
这种规范看起来更适合POST或PUT请求。
有关GET大小请求限制,请参阅此SO问题:maximum length of HTTP GET request?