java模擬http請求給手機發短信

    private static final String SMS_USER = "*****";
    private static final String SMS_PWD = "*****";
    private static final String SMS_METHOD_SEND = "*****";
/**
	 * 註冊的激活碼
	 * @param mobile
	 * @param code
	 * @throws IOException
	 */
	public static void sendActiveSMS(String mobile, String code) throws IOException {
		 HttpClient client = new HttpClient();
		 PostMethod post = new PostMethod("*************************"); 
		 post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");//在頭文件中設置轉碼
		 NameValuePair[] data ={ 
				 new NameValuePair("action", SMS_METHOD_SEND),
				 new NameValuePair("user", SMS_USER),
				 new NameValuePair("mobile", mobile),
				 new NameValuePair("content","***網站註冊驗證碼:" + code + ",如非您本人操作,本信息可忽略。全國服務熱線4000178999。"),
				 new NameValuePair("time",""),
				 new NameValuePair("msgid",""),
				 new NameValuePair("hashcode",SMS_PWD)};
		 post.setRequestBody(data);
    
		 client.executeMethod(post);
		 Header[] headers = post.getResponseHeaders();
		 int statusCode = post.getStatusCode();
		 for(Header h : headers) {
		 }
		 String result = new String(post.getResponseBodyAsString().getBytes("UTF-8")); 
    
		 post.releaseConnection();
	}


發佈了67 篇原創文章 · 獲贊 17 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章