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