SMS短信發送(java)

public static void main(String[] args) throws Exception {
		
		HttpClient client = new HttpClient();  
        PostMethod post = new PostMethod("http://sms.webchinese.cn/web_api/");  
        post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=gbk");// 在頭文件中設置轉碼  
        NameValuePair[] data = { new NameValuePair("Uid", "TroubleWang"), // 註冊的用戶名  
                new NameValuePair("Key", "d41d8cd98f00b204e980"), // 註冊成功後,登陸網站使用的密鑰  
                new NameValuePair("smsMob", "15011045705"), // 手機號碼  
                new NameValuePair("smsText", "【汪澤欣】您的測試用例已經成功發送") };//設置短信內容        
        post.setRequestBody(data);  
        
        client.executeMethod(post);  
        Header[] headers = post.getResponseHeaders();  
        int statusCode = post.getStatusCode();  
        System.out.println("statusCode:" + statusCode);  
        for (Header h : headers) {
            System.out.println(h.toString());  
        }  
        String result = new String(post.getResponseBodyAsString().getBytes(  
                "gbk"));  
        System.out.println(result);  
        post.releaseConnection(); 
		
	}
相關文章
相關標籤/搜索