我正在尝试将图像的字节数组发送到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();
}
?>
非常感激你的帮助.
解决方法:
如果解决了这个问题,我就不会支持,但该网址未进行编码.您可以先尝试一下.
$jsonResponse = @file_get_contents("http://localhost/example/json.htm?action=sendBuzzRequest&email=test%40test.com&pass=test1234&buzz=" . urlencode($buzz));