开发者

Connecting to an ASP.Net web service from PHP and retrieving data as JSON

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开发者_JAVA百科-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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜