3

I'm trying to send byte array of image to my webservice in json object.But, It the request never hits my server. If I send just an empty array it hits the server and returns the json response. Below is my code. What is wrong with this code

<?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();
}
?>

Your Help is very much appreciated.

2 Answers2

2

i'm not shore if this solves it but the url is not encoded. You can try that first.

$jsonResponse = @file_get_contents("http://localhost/example/json.htm?action=sendBuzzRequest&email=test%40test.com&pass=test1234&buzz=" . urlencode($buzz));
RTB
  • 5,773
  • 7
  • 33
  • 50
  • @Vinayak If my anwser helped, please accept it. If not how can we help you, and what's the status of the problem? – RTB Jul 18 '12 at 09:36
1

As per comments, seems that you're probably reaching the maximum size of a GET request..

That sort of spec looks more appropriate for a POST or PUT request..

See this SO question for GET size request limits: maximum length of HTTP GET request?

Community
  • 1
  • 1
Ben
  • 20,737
  • 12
  • 71
  • 115