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"=>"[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.

5
  • 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.. Commented Jun 14, 2012 at 12:06
  • and the fact than an empty array works would seem to further confirm that assumption.. Commented Jun 14, 2012 at 12:07
  • Another relevant entry on GET size limit... stackoverflow.com/questions/2659952/… Commented Jun 14, 2012 at 12:08
  • Hurraaaaaaay. POST did the trick... Thanks! a Million. Commented Jun 14, 2012 at 14:03
  • Cool. I've put that as an answer then.. Commented Jun 14, 2012 at 23:36

2 Answers 2

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));
Sign up to request clarification or add additional context in comments.

1 Comment

@Vinayak If my anwser helped, please accept it. If not how can we help you, and what's the status of the problem?
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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.