android端向服务器提交请求的几种方式
1、GET方式
其实GET方式说白了,就是拼接字符串。。最后拼成的字符串的格式是: path ? username= ....& password= ......
public boolean loginByHttpClientPost(String path,String username , String password)throws Exception{HttpClient httpClient = new DefaultHttpClient();HttpPost httpPost = new HttpPost(path);List<NameValuePair> parameters = new ArrayList<NameValuePair>();parameters.add(new BasicNameValuePair("username", username));parameters.add(new BasicNameValuePair("password", password));UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters,"utf-8");httpPost.setEntity(entity);HttpResponse httpResponse = httpClient.execute(httpPost); if(httpResponse.getStatusLine().getStatusCode() == 200){ return true; } return false;}