怎么通过JSON发送个Http 请求?
我要做个登录功能,所以想用JSON发送http请求,返回的回应也是JSON的,该怎么做?求大神给个简答的例子学些一下,谢谢了。...
我要做个登录功能,所以想用JSON发送http 请求,返回的回应也是JSON的,该怎么做?求大神给个简答的例子学些一下,谢谢了。
展开
2013-08-05
展开全部
试试这个代码: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); }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询