该类是用来调用url 获取json串的

2021-02-10 20:18

阅读:399

标签:cep   set   ring   rri   client   ram   import   tpc   err   

举例:有一个url可以返回一个人名,用该类的HttpClientRequest()方法 传入url 也可获得人名;
   params 这个参数可为空


import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
public class HttpClientUtils {
public static void threadHttpClientRequest(final String url,final String params){
new Thread(new Runnable() {
@Override
public void run() {
HttpClientUtils.HttpClientRequest(url, params);
}
}).start();
}
public static String HttpClientRequest(String httpRequestUrl,String params){
String result = "";
HttpClient httpClient = new HttpClient();
PostMethod post = new PostMethod(httpRequestUrl);
post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
post.setRequestBody(params);
try {
httpClient.executeMethod(post);
result = post.getResponseBodyAsString();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
}

该类是用来调用url 获取json串的

标签:cep   set   ring   rri   client   ram   import   tpc   err   

原文地址:https://www.cnblogs.com/x-x-f/p/13049040.html


评论


亲,登录后才可以留言!