跨服务器传参数(一个、多个)

来源:互联网 发布:php eval 解密 编辑:程序博客网 时间:2024/06/03 17:58
                   String url = "http://118.190.10.236/processEmailForgotPassword.action?emails="+email;    
                    //创建一个默认的HttpClient    
                    HttpClient httpclient = new DefaultHttpClient();    
                    try {    
                        //以post方式请求网页   
                        HttpPost httppost = new HttpPost(url);    
                        //添加HTTP POST参数    
                        List <NameValuePair> nvps = new ArrayList <NameValuePair>();    
                        nvps.add(new BasicNameValuePair("password", password)); //设置传递的参数
                        nvps.add(new BasicNameValuePair("title", title)); 
                
                        //将POST参数以UTF-8编码并包装成表单实体对象    
                        httppost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));  
                        //打印请求地址    
                        System.out.println("executing request " + httppost.getRequestLine().getUri());    
                        //创建响应处理器处理服务器响应内容    
                        ResponseHandler<String> responseHandler = new BasicResponseHandler();    
                        //执行请求并获取结果    
                        String responseBody = httpclient.execute(httppost, responseHandler);    
                        System.out.println(responseBody);    
                    }catch(Exception e){  
                        e.printStackTrace();  
                    }finally {    
                        // 当不再需要HttpClient实例时,关闭连接管理器以确保释放所有占用的系统资源    
                        httpclient.getConnectionManager().shutdown();    
                    }   
原创粉丝点击