
服务器类型:基于REST的API,使用JSON进行数据传输
Content-type:application / Json
接受:application / Json
内容长度:47
{ “用户名”: “ABCD”,“密码”: “1234”}
我可以传递这些标题,但我似乎无法通过这些参数“用户名”,“密码”.这是我的代码:
httpClIEnt clIEnt = new DefaulthttpClIEnt(); httpPost post = new httpPost("http://www.mymi5.net/API/auth/login"); List<nameValuePair> pairs = new ArrayList<nameValuePair>(); pairs.add(new BasicnameValuePair("username","abcd")); pairs.add(new BasicnameValuePair("password","1234")); post.setheader("Content-type","application/Json"); post.setheader("Accept","application/Json"); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs,"UTF-8"); post.setEntity(entity); httpResponse response = clIEnt.execute(post); 我试图调试,但不能看到实体是否正确连接…我做错了什么?
提前致谢.
玛斯
httpClIEnt clIEnt = new DefaulthttpClIEnt(); httpPost post = new httpPost("http://www.mymi5.net/API/auth/login"); post.setheader("Content-type","application/Json");JsONObject obj = new JsONObject();obj.put("username","abcd");obj.put("password","1234"); post.setEntity(new StringEntity(obj.toString(),"UTF-8")); httpResponse response = clIEnt.execute(post); 总结 以上是内存溢出为你收集整理的Android:Http文章,参数不工作全部内容,希望文章能够帮你解决Android:Http文章,参数不工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)