import org.apache.http.message.BasicNameValuePair;
private String getServerData(String returnString) {
InputStream is = null;
String result = "";
//the year data to send
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("year","1970"));
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(KEY_121);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
我的問題......任何人都可以解釋我的這段代碼嗎?
是什麼BasicNameValuePair類呢?
是什麼這塊線做
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
是什麼is = entity.getContent();
辦?並且我可以在BasicNameValuePair類中傳遞多個值。我可以完全通過一個VO而不是這個。
像下面...
nameValuePairs.add(new BasicNameValuePair("year","1970","sas","saassa","sas","asas"));
+1爲了準確和解釋得好。 – Mikaveli 2011-01-25 10:38:55
我已更新我的問題 – theJava 2011-01-25 10:56:48