手機短信發送

//實現短信發送:下面把相關提示內容換成他人手機號和要發送的信息就能讓對方收到你的短信,填好後運行下就發送成功了 
public class Message {
	public static void main(String[] args) throws Exception {
		HttpClient client = new HttpClient();
		PostMethod post = new PostMethod("http://utf8.sms.webchinese.cn/");  //Utf-8編碼Url
		post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");// 在頭文件中設置轉碼
		NameValuePair[] data = { new NameValuePair("Uid", "註冊接口號"), new NameValuePair("Key", "註冊密鑰"), new NameValuePair("smsMob", "接收短信的手機號"), 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("utf-8"));
		System.out.println(result);
		post.releaseConnection();
	}
}
/*須要導入的jar包
 commons-logging-1.1.1.jar
 commons-httpclient-3.1.jar
 commons-codec-1.4.jar */
相關文章
相關標籤/搜索