发送json post使用php [英] Send json post using php
问题描述
我有这些资料:
{
userID:'a7664093-502e-4d2b-bf30-25a2b26d6021' ,
itemKind:0,
value:1,
description:'Boasaudaá'o。',
itemID:'03e76d0a-8bab-11e0-8250-000c29b481aa'
}
我需要发布到json url:
http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Account/CreditAccount
使用php
如何发送此帖子?
更新
这是一个很老的答案。我发现 Guzzle库非常易于在PHP中使用HTTP。
你真的需要发布JSON数据吗?
我知道的最好的方法是通过Zend Framework的HTTP客户端。
有关原始帖子详情,请参阅此处 - http://framework.zend.com/manual/en/zend.http.client.advanced.html#zend.http.client.raw_post_data
这将像
$ data = array(
'userID' =>'a7664093-502e-4d2b-bf30-25a2b26d6021',
'itemKind'=> 0,
'value'=> 1,
'description'=& boasaudaáo。',
'itemID'=>'03e76d0a-8bab-11e0-8250-000c29b481aa'
);
$ json = json_encode($ data);
$ client = new Zend_Http_Client($ uri);
$ client-> setRawData($ json,'application / json') - > request('POST');
I have this data:
{
userID: 'a7664093-502e-4d2b-bf30-25a2b26d6021',
itemKind: 0,
value: 1,
description: 'Boa saudaÁ„o.',
itemID: '03e76d0a-8bab-11e0-8250-000c29b481aa'
}
and I need to post into json url: http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Account/CreditAccount
using php how can I send this post?
Update
This is a pretty old answer. I find the Guzzle library very easy to use for working with HTTP in PHP.
Do you actually need to post JSON data? If so, you're looking at a raw HTTP post.
The best method I know of to do this is via Zend Framework's HTTP client.
See here for raw post details - http://framework.zend.com/manual/en/zend.http.client.advanced.html#zend.http.client.raw_post_data
It would be something like
$data = array(
'userID' => 'a7664093-502e-4d2b-bf30-25a2b26d6021',
'itemKind' => 0,
'value' => 1,
'description' => 'Boa saudaÁ„o.',
'itemID' => '03e76d0a-8bab-11e0-8250-000c29b481aa'
);
$json = json_encode($data);
$client = new Zend_Http_Client($uri);
$client->setRawData($json, 'application/json')->request('POST');
这篇关于发送json post使用php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!