PHP   发布时间:2019-11-11  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了POST一个JSON格式的数据给Restful服务实例详解大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

在Android/Java平台上实现POST一个json数据:

ject jsonObj = new JSONObject(); jsonObj.put("username",userName); jsonObj.put("apikey",apikey); // Create the POST object and add the parameters httpPost httpPost = new httpPost(url); StringEntity entity = new StringEntity(jsonObj.toString(),http.UTF_8); entity.setContentType("application/json"); httpPost.setEntity(entity); httpClient client = new DefaulthttpClient(); httpResponse response = client.execute(httpPost);

用curl可执行如下命令:

{"phone":"13521389587","password":"test"}' http://domain/apis/users.json

用jQuery:

{ url:url,type:"POST",data:data,contentType:"application/json; charset=utf-8",dataType:"json",success: function(){ ... } })

php用cUrl实现:

"Hagrid","age" => "36"); $data_String = json_encode($data); $ch = curl_init('http://api.local/rest/users'); curl_setopt($ch,CURLOPT_CUSTOMrequEST,"POST"); curl_setopt($ch,CURLOPT_POSTFIELDS,$data_String); curl_setopt($ch,CURLOPT_RETURNTRANSFER,truE); curl_setopt($ch,CURLOPT_httpHEADER,array( 'Content-Type: application/json','Content-Length: ' . strlen($data_String)) ); $result = curl_exec($ch);

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

大佬总结

以上是大佬教程为你收集整理的POST一个JSON格式的数据给Restful服务实例详解全部内容,希望文章能够帮你解决POST一个JSON格式的数据给Restful服务实例详解所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: