1、http 请求json数据 请求头怎么写
Http之Get/Post请求区别 1.HTTP请求格式: [] 在HTTP请求中,第一行必须是一个请求行(request line),用来说明请求类型、要访问的资源以及使用的HTTP版本。紧接着是一个首部(header)小节,用来说明服务器要使用的附加信息。
2、content-type application/json 请求 服务端怎么获取请求数据?
在Android/java平台上实现POST一个json数据:
JSONObject 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可执行如下命令:
curl -l -H "Content-type: application/json" -X POST -d '{"phone":"13521389587","password":"test"}' http://domain/apis/users.json
用jQuery:
$.ajax({
url:url,
type:"POST",
data:data,
contentType:"application/json; charset=utf-8",
dataType:"json",
success: function(){
...
}
})
服务端(Server)是为客户端服务的,服务的内容诸如向客户端提供资源,保存客户端数据。一般大型的服务端都是在linux环境下搭建。
服务端不具备运算能力,因为服务端同时会与多个客户端建立连接,一旦服务端进行运算的话,就会占用大量的资源,从而影响到其他客户端的通信。
服务端是一种有针对性的服务程序。它的主要表现形式以“windows窗口程序”与“控制台”为主。一般大型的服务端都是在linux环境下搭建。运行服务端的电脑称之为“服务器”。
3、怎么通过http请求获取到json数据
得到对方返回的String数据,然后自己做相关转换就可以了。
这里有HTTP请求整套源码:
http://www.sojson.com/blog/123.html然后下面是线上的Demo:
在线HTTP POST/GET ... 接口测试工具
http://www.sojson.com/httpRequest/4、如何使用@RequestBody一个JSONP请求
JSONP意味着jQuery将创建一个<脚本> 与元素的src 指向控制器的URL。
正如你所看到的,这种做法不允许你通过任何数据请求体,所有的数据应在URL中传递查询参数。 数据:{ABC:'123'} 表示 ABC = 123 添加到URL
在控制器端需要使用任何 @RequestParam (绑定inidivial参数)或者 @ModelAttribute (以绑定多个参数到一个对象):
公共返回object getBlahBlah(@RequestParam(“ABC”)INT ABC)抛出异常{...}
5、如何使用Alamofire请求一个JSON数据
搭建一个WCF,这个WCF接收一个JSON,并会返回一个JSON,使用安卓实现连接。
使用Swift,连接它的时候,POST传递字典格式
代码如下:
let parameters: Dictionary<String,AnyObject> = ["userId": id,"pwd":psw]
Alamofire.request(.POST,, parameters: parameters).responseJSON { ( request, response, JSON, error) in
println(request)
println(response)
println(JSON)
println(error)
6、怎么通过JSON发送个Http 请求?
试试这个代码:Button show_data;JSONObject my_json_obj;String path,firstname,lastname;path = " http://192.168.101.123:255/services/services.php?id=9"; HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); HttpEntity entity; HttpResponse response = null; HttpURLConnection urlconn; my_json_obj = new JSONObject(); try { urlconn = (HttpURLConnection) new URL(path).openConnection(); urlconn.setConnectTimeout(10000); urlconn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(urlconn.getOutputStream(), "UTF-8");my_json_obj.put("sUserName", "test2"); my_json_obj.put("sPassword", "123456");writer.write(my_json_obj.toString()); writer.close();if(true) { String temp; temp = WebRequestCall(my_json_obj); //Log.i("Reply", temp); }
7、如何创建一个json 请求body
一个标准的 JSON 请求的实现过程:HttpPost request = new HttpPost(url);// 先封装一个 JSON 对象JSONObject param = new JSONObject();param.put("name", "rarnu");param.put("password", "123456");// 绑定到请求 EntryStringEntity se = new StringEntity(param.toString()); request.setEntity(se);// 发送请求HttpResponse httpResponse = new DefaultHttpClient().execute(request);// 得到应答的字符串,这也是一个 JSON 格式保存的数据String retSrc = EntityUtils.toString(httpResponse.getEntity());// 生成 JSON 对象JSONObject result = new JSONObject( retSrc);String token = result.get("token");
8、json在线解析
我之前也遇到这个问题了,现在解决了,代码给你参考下
//POST方式,需要Authorization,json_post_out()输出数组形式的数据 $url为请求地址,$data为json数据格式
function json_post_out($url,$data,$auth){
header("Content-type:text/html; charset=utf-8");
$headers['Authorization'] = $auth;
// 参数数组
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POST, 1 );
//curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt($ch,CURLOPT_ENCODING,"gzip");//将json数据压缩 重要!!!!!
$return=curl_exec ( $ch );
curl_close ( $ch );
$json = preg_replace('/HTTP(.*)gzip/is','',$return);//解压缩 重要!!!!!
$json = json_decode($json);
var_mp($json);
}
9、content-type application/json 请求 服务端怎么获取请求数据
在Android/java平台上实现POST一个json数据:
JSONObject 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可执行如下命令:
curl -l -H "Content-type: application/json" -X POST -d '{"phone":"13521389587","password":"test"}' http://domain/apis/users.json
用jQuery:
$.ajax({
url:url,
type:"POST",
data:data,
contentType:"application/json; charset=utf-8",
dataType:"json",
success: function(){
...
}
})
服务端(Server)是为客户端服务的,服务的内容诸如向客户端提供资源,保存客户端数据。一般大型的服务端都是在linux环境下搭建。
服务端不具备运算能力,因为服务端同时会与多个客户端建立连接,一旦服务端进行运算的话,就会占用大量的资源,从而影响到其他客户端的通信。
服务端是一种有针对性的服务程序。它的主要表现形式以“windows窗口程序”与“控制台”为主。一般大型的服务端都是在linux环境下搭建。运行服务端的电脑称之为“服务器”。
10、html5调用json数据接口怎么写
用js的ajax,这个是jquery的一个简单例子,纯js的会稍微复杂点,
$.ajax({
type: "post",//请求方式
dataType: "json",//数据类型
url: "",//请求地址
success: function (msg) {
//成功之后调用
}
});