Android——POST传输(一)

 

//貌似必须要是异步的我把它放在AsyncTask里面执行一下就是代码例子

HttpResponse httpResponse = null;
try {
String urlString = "http://10.10.1.203:3651/WebServicesForAndroid/AndoidHandler.ashx";
HttpPost httpPost = new HttpPost(urlString);
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("Method", "addQZXS"));
list.add(new BasicNameValuePair("Name", nameEditText.getText()
.toString()));
list.add(new BasicNameValuePair("Phone", phoneEditText
.getText().toString()));
list.add(new BasicNameValuePair("lb_id",
""));
list.add(new BasicNameValuePair("Content", contentEditText
.getText().toString()));
list.add(new BasicNameValuePair("zb_id",
itID.toString()));
list.add(new BasicNameValuePair("Image",
get_Add_InspectionTable_Image_String()));

httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
httpResponse = new DefaultHttpClient().execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
String result = EntityUtils.toString(httpResponse
.getEntity());
Log.v("msg", result);
Gson gson = new Gson();
java.lang.reflect.Type listType = new TypeToken<LinkedList<HashMap<String, String>>>() {
}.getType();
resultmessage = gson.fromJson(result, listType);
}
} catch (Exception e) {
e.printStackTrace();
}

//第一次接触POST传输,感觉应该能再改善

Android——POST传输(一),,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。