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


     


     

  • 相关阅读:
    配置navigation bar外观
    加急审核
    UIButton中setTitleEdgeInsets和setImageEdgeInsets的使用
    打开某个好友的聊天界面
    ALAssets的两种用法
    更改appstore开发商名字
    回调函数的使用
    相应字体所占的位置大小
    IOS的变量前加extern和static字段
    iOS开发代码规范(通用)
  • 原文地址:https://www.cnblogs.com/nafio/p/9137776.html
Copyright © 2020-2023  润新知