在线客服 联系我们 返回顶部
企业动态 技术分享 行业动态

Java调用Http接口(3)

2019-12-06

commons-httpclient原来是apache commons项目下的一个组件,现已被httpcomponents项目所替代;作为调用http接口的一种挑选,本文介绍下其使用方法。文中所使用到的软件版别:java 1.8.0_191、commons-httpclient 3.1。

拜见java调用http接口--编写服务端 

public static void get {
 try {
 string requestpath = "http://localhost:8080/webframe/demo/test/getuser?userid=1000 username=" + urlencoder.encode;
 httpclient httpclient = new httpclient;
 getmethod get = new getmethod;
 int status = httpclient.executemethod;
 if  {
 system.out.println);
 } else {
 system.out.println;
 } catch  {
 e.printstacktrace;
}
public static void multi {
 try {
 string requestpath = "http://localhost:8080/webframe/demo/test/multi";
 httpclient httpclient = new httpclient;
 postmethod post = new postmethod;
 file file = new file;
 part[] parts = {new filepart, new stringpart, new stringpart};
 post.setrequestentity));
 int status = httpclient.executemethod;
 if  {
 system.out.println);
 } else {
 system.out.println;
 } catch  {
 e.printstacktrace;
}
在线咨询
Copyright © 2018 九五至尊网址九五至尊网址-九五至尊下载app赌博 All Rights Reserved