国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

如何用java模擬ajax數(shù)據(jù)發(fā)送請(qǐng)求

2019-11-14 14:51:16
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

案例1:

import org.apache.commons.httpclient.*;  import org.apache.commons.httpclient.methods.*;  import org.apache.commons.httpclient.params.HttpMethodParams;    import java.io.*;    public class HttpClientTutorial {        PRivate static String url = "http://10.129.39.149:8090/Ajax/loginMgt/login.action";      public static void method(HttpClient client,String url,String body){        PostMethod  method = new PostMethod(url);          //"count":10,"ignoreCase":"false","paras":["a%"],"queryId":"getMenu"          NameValuePair[] postData = new NameValuePair[]{};            //postData[0] = new NameValuePair("count", 10);           method.setRequestBody(body);//addParameters(postData);                               // Provide custom retry handler is necessary          /*method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,                  new DefaultHttpMethodRetryHandler(3, false));*/            try {            // Execute the method.            int statusCode = client.executeMethod(method);              if (statusCode != HttpStatus.SC_OK) {              System.err.println("Method failed: " + method.getStatusLine());            }              // Read the response body.            byte[] responseBody = method.getResponseBody();              // Deal with the response.            // Use caution: ensure correct character encoding and is not binary data            System.out.println(new String(responseBody,"utf-8"));          } catch (HttpException e) {              System.err.println("Fatal protocol violation: " + e.getMessage());              e.printStackTrace();            } catch (IOException e) {              System.err.println("Fatal transport error: " + e.getMessage());              e.printStackTrace();            } finally {              // Release the connection.              method.releaseConnection();            }      }        public static void main(String[] args) {      // Create an instance of HttpClient.      HttpClient client = new HttpClient();            String body ="[{/"userId/":1,/"passWord/":1}]";      // Create a method instance.      method(client,url,body);            url = "http://10.129.39.149:8090/ajax/getInitValueArr.action";            body = "[{/"count/":10,/"ignoreCase/":/"false/",/"paras/":[/"a%/"],/"queryId/":/"getMenu/"}]";      method(client,url,body);    }  }

案例2:

   HttpClient c = new HttpClient();        HttpMethod m = new GetMethod(); String path =msnListPath+"?account="+userSimpleInfo.getMsnAccount()+"&type=msn&uid="+userSimpleInfo.getPassportId()+"&pwd="+userSimpleInfo.getMsnPassword();    m.setPath(path);     String response="";	    int status = 0;     try {     status  = c.executeMethod(m);	if(status == HttpStatus.SC_OK) {	byte[] rbytes = m.getResponseBody(); response = new String(rbytes,"UTF-8"); return  response;	} } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "error";



發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平凉市| 景洪市| 扬中市| 龙川县| 迁西县| 桂阳县| 弥渡县| 宁都县| 湾仔区| 阳新县| 大同县| 株洲市| 吴忠市| 讷河市| 佛山市| 玉林市| 云浮市| 长宁区| 都安| 东乡族自治县| 邛崃市| 潮安县| 枣强县| 定远县| 长阳| 山东省| 永登县| 龙海市| 峨眉山市| 广丰县| 十堰市| 颍上县| 张家口市| 乐都县| 宁津县| 登封市| 洪雅县| 凤阳县| 四川省| 莒南县| 铜山县|