微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从PHP发送字节数组

我正在尝试将图像的字节数组发送到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));

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐