客户端发送Json数据问题
2017-01-01 00:36
387 查看
完整地址为
http://www.yidan360.com/gckjapi/userLogin?data={"userName":"GCKJ","password":"123456","deviceId":"XXX","systemId":"XXX"}
但就是登陆不上去
public class Connector {
public static String sendPost(String servlet,JSONObject param) throws JSONException{
String result="none";
String url="http://www.yidan360.com/gckjapi/userLogin?data=";
HttpClient client=new DefaultHttpClient();
HttpPost post=new HttpPost(url);
System.out.println(url);
post.addHeader("Accept","application/json");
post.addHeader("Content-Type","application/json");//还可以自定义增加header
try{
JSONObject param1 = new JSONObject();//定义json对象
param1.put("userName","GCKJ");
param1.put("password","123456");
System.out.println(url+param.toString());
StringEntity se=new StringEntity(param1.toString());
post.setEntity(se);
System.out.println(EntityUtils.toString(post.getEntity()));
HttpResponse res=client.execute(post);
if(res.getStatusLine().getStatusCode()==200){
result=EntityUtils.toString(res.getEntity());
}
}catch(Exception e){
result="nothing";
e.printStackTrace();
}finally {
client.getConnectionManager().shutdown();
}
return result;
}
}
http://www.yidan360.com/gckjapi/userLogin?data={"userName":"GCKJ","password":"123456","deviceId":"XXX","systemId":"XXX"}
但就是登陆不上去
public class Connector {
public static String sendPost(String servlet,JSONObject param) throws JSONException{
String result="none";
String url="http://www.yidan360.com/gckjapi/userLogin?data=";
HttpClient client=new DefaultHttpClient();
HttpPost post=new HttpPost(url);
System.out.println(url);
post.addHeader("Accept","application/json");
post.addHeader("Content-Type","application/json");//还可以自定义增加header
try{
JSONObject param1 = new JSONObject();//定义json对象
param1.put("userName","GCKJ");
param1.put("password","123456");
System.out.println(url+param.toString());
StringEntity se=new StringEntity(param1.toString());
post.setEntity(se);
System.out.println(EntityUtils.toString(post.getEntity()));
HttpResponse res=client.execute(post);
if(res.getStatusLine().getStatusCode()==200){
result=EntityUtils.toString(res.getEntity());
}
}catch(Exception e){
result="nothing";
e.printStackTrace();
}finally {
client.getConnectionManager().shutdown();
}
return result;
}
}
相关文章推荐
- 客户端发送Json数据问题
- 关于TCP服务器端与客户端数据发送的问题
- SpringMVC客户端发送json数据时报400错误
- HttpPost发送JSON数据中文乱码问题。
- Java客户端向twisted服务器发送数据中遇到的问题
- C#中用Socket网络编程的问题,从客户端把数据发送到指定的IP和端口
- 在线客户端:使用AJAX发送JSON数据
- Tcp服务端一直sleep,客户端不断发送数据产生的问题
- 类型:JQuery;问题:ajax调用ashx文件;结果:ashx文件怎么获取$.ajax()方法发送的json数据
- 一个包含Jersey库的简单Web Service以及一个发送Json数据的Java客户端
- iOS客户端发送json数据,java(servlet)服务器接受json数据
- 关于servlet服务端接收客户端发送的List<?>数据的问题
- 从安卓客户端向服务器端发送JSON格式的数据
- Tcp服务端一直sleep,客户端不断发送数据产生的问题
- 在使用ajax向后台发送json数据,存在格式不正确的问题
- 关于客户端与服务器ajax使用json数据交互,出现中文乱码或因包含html标答而报错的问题(base64加密)
- 客户端POST发送json数据给服务端,客户端端接收服务器端json数据响应
- Android—Volley:接收服务端发送的json数据乱码问题解决
- Tcp服务端一直sleep,客户端不断发送数据产生的问题
- 后台发送json数据,将List转化成json数据时执行到JSONArray distJson=JSONArray.fromObject(ChapterList)就报错的问题解决方案