webservice-接口测试3(post请求)


package cn.it.ws.webservice;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

import java.io.IOException;

public class phoneClientPost {




    public void GetRequest(String number) throws IOException {
        //创建浏览器
        HttpClient httpClient = new HttpClient();
        //填写数据,发送get或者post请求
        GetMethod getMethod = new GetMethod("http://ws.webxml.com.cn" +
                "/WebServices/MobileCodeWS.asmx/"+
                "getMobileCodeInfo?mobileCode="+number+"&userID=");
        //发送请求,并用code接收返回状态码
        int code = httpClient.executeMethod(getMethod);
        System.out.println("http:状态码为:"+code);
        //获取返回结果
        String result = getMethod.getResponseBodyAsString();
        System.out.println("Get方法返回结果:"+result);
    }

    public void PostRequest(String number) throws IOException {
        //创建浏览器
        HttpClient httpClient = new HttpClient();
        //填写数据,发送get或者post请求
        PostMethod postMethod = new PostMethod("http://ws.webxml.com.cn" +
                "/WebServices/MobileCodeWS.asmx/getMobileCodeInfo");
        postMethod.setParameter("mobileCode",number);
        postMethod.setParameter("userID","");

        //发送请求,并用code接收返回状态码
        int code = httpClient.executeMethod(postMethod);
        System.out.println("http:状态码为:"+code);
        //获取返回结果
        String result = postMethod.getResponseBodyAsString();
        System.out.println("Post方法返回结果:"+result);
    }



    public static void main(String[] args) throws IOException {

        phoneClientPost client = new phoneClientPost();
        client.PostRequest("134288888888");




    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM