Android_网络编程(1)

来源:互联网 发布:scratch live for mac 编辑:程序博客网 时间:2024/05/18 03:51
1.post请求
    //发送Post请求
   dopost(mEtInPut.getText().toString());
  //http客户端
    DefaultHttpClient client=newDefaultHttpClient():
   //天气查询
   HttpPost httppost=newHttpPost("http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather");
   //post运作传送变量必须用nameValuepair【】数组储存
   List Params=new ArrayList();
   params.add(newBasicNameValuePair("theCityCode",val)); 
   params.add(newBasicNameValuePair("theUserID",""));
  //编码格式
   UrlEncodeFormEntity p_entity=new UrlEncodedFormEntity(Params,"utf-8");
  //将post数据放入http请求
   httpPost.setEntity(p_entity);
 //发出实际的http  post请求
   HttpResponseresponse=client.execute(httpPost);
 //若状态编码为200
  mreturnConnection="EntityUtils.toString(response.getEntiry());
0 0