91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

發送帶參數的get請求,并解決httpclient編碼問題

發布時間:2020-07-18 17:03:11 來源:網絡 閱讀:1645 作者:拖鞋的暢想 欄目:軟件技術

package cn.wemart.httppost;


import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.UnsupportedEncodingException;

import java.net.URI;

import java.net.URISyntaxException;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.http.HttpEntity;

import org.apache.http.NameValuePair;

import org.apache.http.client.ClientProtocolException;

import org.apache.http.client.entity.UrlEncodedFormEntity;

import org.apache.http.client.methods.CloseableHttpResponse;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;

import org.apache.http.message.BasicNameValuePair;

import org.apache.http.protocol.HTTP;

import org.apache.http.util.EntityUtils;

import org.dom4j.DocumentException;


public class ExecuteGet {


/**

* 組裝請求參數

* @param keyVlaueList

*/

public static Map<String ,String> setPostPara(String[][] keyVlaueList) throws DocumentException{

Map<String ,String> map = new HashMap<String ,String>();

for(int i = 0;i<keyVlaueList.length;i++)

{

map.put(keyVlaueList[i][0],keyVlaueList[i][1]);

}

return map;

}

/**

* 獲取接口返回字符串

* @param url

* @throws DocumentException 

* @throws URISyntaxException 

*/

public static String getGetMethodResponse(String url,String[][] keyVlaueList) {

String xmlStr =null;

String Str;

try {

//把鍵值對轉換成JSON格式串

Map<String, String> postMap;

postMap = setPostPara(keyVlaueList);

JSONObject object = JSONObject.fromObject(postMap);

List<NameValuePair> postPara = new ArrayList<NameValuePair>();

postPara.add(new BasicNameValuePair("para",object.toString()));

System.out.println("+++++para="+object.toString()+"+++++");

//發送轉碼過的字符串,發送

CloseableHttpClient httpclient = HttpClients.createDefault();

HttpGet httpget = new HttpGet(url);

       String sendstr = EntityUtils.toString(new UrlEncodedFormEntity(postPara,HTTP.UTF_8));  

httpget.setURI(new URI(httpget.getURI().toString() + "?" + sendstr));

CloseableHttpResponse response = httpclient.execute(httpget);

//處理response的中文編碼

BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(),"UTF-8"));

StringBuffer sb = new StringBuffer();

while ((Str = reader.readLine()) != null) {

sb.append(Str).append("\n");

}

xmlStr = sb.toString();


} catch (UnsupportedEncodingException e) {

e.printStackTrace();

} catch (ClientProtocolException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (URISyntaxException e) {

e.printStackTrace();

} catch (DocumentException e) {

e.printStackTrace();

}

return xmlStr;

}

}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

北川| 政和县| 武山县| 滁州市| 建始县| 新龙县| 高唐县| 正镶白旗| 河源市| 获嘉县| 樟树市| 舒兰市| 克拉玛依市| 麻江县| 珲春市| 宣威市| 宣恩县| 县级市| 门源| 天全县| 南皮县| 类乌齐县| 桓仁| 晋宁县| 剑河县| 大方县| 临高县| 石棉县| 常德市| 北碚区| 泰兴市| 长兴县| 家居| 内江市| 绥化市| 襄汾县| 广南县| 芜湖县| 喜德县| 延庆县| 海门市|