1

I'm having issues connecting to an ASP.Net web service using PHP.

The web service is known to be operational, since it's returning data when we connect using Javascript from the same domain, but when I attempt to connect using PHP I receive the following error:


HTTP/1.1 500 Internal Server Error Content-Type: application/json; charset=utf-8 Server: Microsoft-IIS/7.5 jsonerror: true X-Powered-By: ASP.NET Date: Tue, 17 May 2011 03:40:17 GMT Connection: close Content-Length: 819

{"Message":"Invalid JSON primitive: birthday.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\

[etc]

The Content-Type is set to "application/json; charset=utf-8" in PHP, and we are trying to send a parameter called "birthday" using the following POST data in PHP:

$post_data = array(
    'birthday' => 'none'
);

I think the ASP web service is not able to parse the 'birthday' parameter for some reason, but I'm not sure why.

Do I need to explicitly encode the POST data as JSON from PHP before calling the web service?

Thanks.

2
  • 1
    You could try observing the data travelling over the wire with Fiddler or WireShark comparing the working code to the non-working code, and see if there are any differences. Commented May 17, 2011 at 4:28
  • Is the javascript POSTing as well or is it using get? Can you provide the javascript that works Commented May 17, 2011 at 4:46

1 Answer 1

4

May be this web service takes the post data in Json format. If it is then you should use

$post_data = array( 'birthday' => 'none' );
$jsonData =  json_encode ($post_data );

for details json_encode

Sign up to request clarification or add additional context in comments.

1 Comment

You're right. I manually encoded a JSON string and the response was the data I needed. Thanks

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.