webservice-接口测试2(get请求)
//webservice支持http get和pos请求,但不规范,应该用soap更加规范
package cn.it.ws.webservice; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.GetMethod; import java.io.IOException; public class phoneClient3 { public static void main(String[] args) throws IOException { //创建浏览器 HttpClient httpClient = new HttpClient(); //填写数据,发送get或者post请求 GetMethod getMethod = new GetMethod("http://ws.webxml.com.cn" + "/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode=18588888888&userID="); //发送请求,并用code接收返回状态码 int code = httpClient.executeMethod(getMethod); System.out.println("http:状态码为:"+code); //获取返回结果 String result = getMethod.getResponseBodyAsString(); System.out.println("result:"+result); } }
导入的jar包:


浙公网安备 33010602011771号