android端
public void ppost() { String uriAPI = "http://xx.xxxx.xx:17777/Nafio/Emulator/test/tempPostWml.jsp"; /*建立HTTP Post连线*/ HttpPost httpRequest =new HttpPost(uriAPI); //Post运作传送变数必须用NameValuePair[]阵列储存 //传参数 服务端获取的方法为request.getParameter("name") List <NameValuePair> params=new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("imei","imei")); params.add(new BasicNameValuePair("wml","我的测试")); try{ //发出HTTP request httpRequest.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));//注意这里要写成utf-8,与jsp对应 //取得HTTP response HttpResponse httpResponse=new DefaultHttpClient().execute(httpRequest); //若状态码为200 ok if(httpResponse.getStatusLine().getStatusCode()==200){ //取出回应字串 String strResult=EntityUtils.toString(httpResponse.getEntity()); }else{ Log.e("n", "b"); } }catch(ClientProtocolException e){ e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
服务端jsp
<%@ page language="java" contentType="text/html; charset=gb2312"%> <%@ page import="temp.TempRecordWml" %> <!--request.setCharacterEncoding("utf-8"); --> <% String imei = new String(request.getParameter("imei").getBytes("ISO-8859-1"),"utf-8"); String wml = new String(request.getParameter("wml").getBytes("ISO-8859-1"),"utf-8"); TempRecordWml t=new TempRecordWml(); String str = t.createConfigFile(imei,wml); out.println("中文"); response.getWriter().write("imei->"+imei+" "+"wml->"+wml); %>