zoukankan      html  css  js  c++  java
  • android与jsp http post方式通信

    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);
    %>


     


     

  • 相关阅读:
    JSP具体条款——response对象
    智课雅思词汇---三、aud和auto和bene是什么意思
    如何实现无刷新图片上传
    智课雅思词汇---二、词根acu和acr
    FormData是什么
    ajax如何上传文件(整理)
    js插件---评分插件Rating如何使用
    js插件---Amaze UI dialog如何使用
    js插件---layer.js使用体验是怎样
    算法答疑---06:月度开销
  • 原文地址:https://www.cnblogs.com/nafio/p/9137776.html
Copyright © 2011-2022 走看看