亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

post請求的參數如何添加?

post請求的參數如何添加?老師的視頻中只是一個字符串,能否幫忙指出如何添加post方法攜帶的參數?謝謝老師

正在回答

1 回答

public static String httpPost(String url,List<BasicNameValuePair> list) {

String result = null;

RequestConfig requestConfig = RequestConfig.custom()

.setConnectTimeout(5000) ? //設置連接超時時間

.setConnectionRequestTimeout(5000) // 設置請求超時時間

.setSocketTimeout(5000)

.setRedirectsEnabled(true)//默認允許自動重定向

.build();

CloseableHttpClient closeableHttpClient = HttpClients.createDefault();

HttpPost httpPost = new HttpPost(url);

httpPost.setConfig(requestConfig);

try {

UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8");

//設置post請求參數

httpPost.setEntity(entity);

HttpResponse httpResponse = closeableHttpClient.execute(httpPost);

if(httpResponse.getStatusLine().getStatusCode() == 200) {

result = EntityUtils.toString(httpResponse.getEntity());

}

} catch (Exception e) {

e.printStackTrace();

}finally {

try {

closeableHttpClient.close();

} catch (IOException e) {

e.printStackTrace();

}

}

return result;

}


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

post請求的參數如何添加?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號