How to post a JSON-formatted data to a restful service, jsonrestful
To implement a post JSON data on the Android/java platform:
JsonobjectJsonobj= New Jsonobject();Jsonobj.Put("Username",Username);Jsonobj.Put("Apikey",Apikey);Create the POST object and add the parametersHttpPostHttpPost= New HttpPost(Url);StringentityEntity= New Stringentity(Jsonobj.Tostring(),HTTP.utf_8); entity.. Setentityentityhttpclient client = new defaulthttpclient (); httpresponse response = client execute (httppost
Use Curl to execute the following command:
Curl-l-H "Content-type:application/json"-X post-d ' {"Phone": "13521389587", "Password": "Test"} ' http://domain/apis/ Users.json
With jquery:
$ajax ({ Url:url, Type: "POST" Data:data,: "Application/json; Charset=utf-8 ", Datatype:" JSON " , Success: function< Span class= "pun" > () { ... }}) /span>
PHP is implemented with Curl:
1 $data Array ("Name" = "Hagrid", "Age" and " 2",$data _string = Json_encode ($data 3$ch = curl_init (' http://api.local/rest/users ' 4 curl_setopt ($ch , Curlopt_customrequest, "POST" 5 curl_setopt ($ch$data _string ); 6 curl_setopt ($chtrue); 7 curl_setopt ($charray 8 ' Content-type:application/json ', 9 strlen ($data _string$result = curl_exec ($ch );
http://www.bkjia.com/PHPjc/1053805.html www.bkjia.com true http://www.bkjia.com/PHPjc/1053805.html techarticle How to post a JSON-formatted data to a restful service, jsonrestful on the Android/java platform to post a JSON data: jsonobject jsonobj = new Jsonobject (); Jsonobj. Put ("Use ...