Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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"=>"[email protected]");
$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 protected]&pass=test1234&buzz=".$buzz);
echo ($jsonResponse);
} catch(Exception $e)
{
 $e->getMessage();
}
?>

Your Help is very much appreciated.

share|improve this question
1  
you're probably reaching the maximum size of a GET request.. That sort of spec looks more appropriate for a POST or PUT request.. –  Ben Jun 14 '12 at 12:06
    
and the fact than an empty array works would seem to further confirm that assumption.. –  Ben Jun 14 '12 at 12:07
    
Another relevant entry on GET size limit... stackoverflow.com/questions/2659952/… –  Ben Jun 14 '12 at 12:08
    
Hurraaaaaaay. POST did the trick... Thanks! a Million. –  Vinayak Dhulipudi Jun 14 '12 at 14:03
    
Cool. I've put that as an answer then.. –  Ben Jun 14 '12 at 23:36

2 Answers 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));
share|improve this answer
    
@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 9:36

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?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.