色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

httpclient可以跨語言調(diào)用第三方接口嗎

洪振霞2年前20瀏覽0評論

httpclient可以跨語言調(diào)用第三方接口嗎?

簡述

本文主要介紹如何基于HttpClient接口調(diào)用。

所需jar實(shí)例

package httputil_demo;import java.io.IOException;import java.util.ArrayList;import java.util.List;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.NameValuePair;import org.apache.commons.httpclient.methods.PostMethod;import com.alibaba.fastjson.JSONObject;/**** <p>Title: HttputilDemo</p>** <p>Description: http接口請求實(shí)例</p>** @author** @date 2020年6月1日**/public class HttputilDemo {public static void main(String[] args) {String Url = "接口地址";JSONObject jsonparam = new JSONObject();jsonparam.put("key", "value");HttpClient client = new HttpClient();PostMethod method = new PostMethod(Url);client.getParams().setContentCharset("UTF-8");method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");List<NameValuePair> paramList = new ArrayList<NameValuePair>();for (String key : jsonparam.keySet()) {paramList.add(new NameValuePair(key, jsonparam.getString(key)));}NameValuePair[] array = paramList.toArray(new NameValuePair[paramList.size()]);method.setRequestBody(array);String SubmitResult = "";try {client.executeMethod(method);SubmitResult = method.getResponseBodyAsString();System.out.println(SubmitResult);} catch (IOException e) {e.printStackTrace();} finally {method.releaseConnection();}}}

請求結(jié)果代碼目錄

如果解決了你的疑惑,請點(diǎn)點(diǎn)關(guān)注和評論,謝謝支持。

正春華枝俏,待秋實(shí)果茂,與君共勉。