Package com.google;
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
Import org.apache.commons.httpclient.HttpClient;
Import Org.apache.commons.httpclient.methods.PostMethod;
public class Sendsms {
public static void Main (string[] args) {
String url = "Http://finance.aliyun.com/recharge/sendMessage.json";
String token = "9zud6in0afdn2szfjemkua";
String mobile = "13800138000";
String sendstr = "Chery Fung Root Bank 8888 8888 8888 888";
sendsms ss = new Sendsms ();
String result = Ss.getpostpage (URL, mobile, sendstr, token);
SYSTEM.OUT.PRINTLN (result);
}
public string getpostpage (string URL, String mobile, String sendstr,
String _csrf_token) {
HttpClient client = new HttpClient ();
Postmethod method = new Postmethod (URL);
Method.getparams (). Setcontentcharset ("Utf-8");
Method.setrequestheader ("Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
Method.setrequestheader ("accept-encoding", "GZIP,DEFLATE,SDCH");
Method.setrequestheader ("Accept-language", "zh-cn,zh;q=0.8");
Method.setrequestheader ("Accept-charset", "gbk,utf-8;q=0.7,*;q=0.3");
Method.setrequestheader ("Host", "finance.aliyun.com");
Method.setrequestheader ("Origin", "http://finance.aliyun.com");
Method.setrequestheader ("Connection", "keep-alive");
Method.setrequestheader (
"Referer",
"Http://finance.aliyun.com/account/recharge.htm?spm=0.0.0.0.elRHXV_0.0.0.0.uWxMEt");
Method.setrequestheader (
"User-agent",
"mozilla/5.0 (Windows NT 5.1) applewebkit/535.7 (khtml, like Gecko) chrome/16.0.912.77 safari/535.7");
Method.setrequestheader (
"Cookie",
"JSESSIONID=UM5663B1-YORLH533CMAAD3D7NVG72-IDQ1HNPH-HA8; www_aliyun=5ugne0vg8ng4s69bgnbc8c1j23; login_aliyunid= "[email protected]"; login_aliyunid_ticket=qizcr6t7sgxrigm2cb4fgacdbzwizmgdhq6sxxzqg4kfwufyvpev*0*cm58slmt1tjw3_l$ $TPk 34m6umf8qm3z_ Ar76cgyps0p6uimbujw6kvasykof_bnpwu_totnchzboem1kjexdfb9zhynsn5so0; login_aliyunid_csrf=_csrf_tk_1815088030290190; HSSID=1WRQTEJUUMJU3DIXAG_C7QQ1; hsite=6; hsts=1388030291344; cfp0=5fwupcghoov2ekqzphy5awfzxdm8gzy9mmwxuxkmrmdfqgpmdjazaugn% 2b8vacgamiuknoxjvj2q8zbflisga1wn0h0ewtw8ellktps4qgskfafs88fki2cu5u7c9cg9hvg9uup% 2bhky8uoegrollfuovtulxjbuyswedqa1p%2fy%2blpna5xwkrqzessqs6wvsph9859zplfhpzltq%2b%2fy% 2b2j24qjkf4vqyskmmpjww3edwd2hkso1xhbdu78aotv10gds6amw3borxb%2fuimawxwx% 2fgzvqdlf0djwg8dxoopg1piv5isw9qxpylltdff%2fs3lgicjwzqgshigfkpfhs21xancx0sqhhy%2bxkbnrd4z5x% 2faoyfyvdesfe9guopyc4cagqmfz5cnmni7kes4tnvgc%2bg%3d%3d; _ga=ga1.2.1860272764.1387960845 ");
Method.setrequestheader ("X-requested-with", "XMLHttpRequest");
Set Request parameters
Method.addparameter ("mobile", mobile);
Method.addparameter ("Sendstr", sendstr);
Method.addparameter ("_csrf_token", _csrf_token);
String responsestr = "";
try {
Client.executemethod (method);
Responsestr = Method.getresponsebodyasstring ();
InputStream Resstream = Method.getresponsebodyasstream ();
BufferedReader br = new BufferedReader (New InputStreamReader (
Resstream));
StringBuffer resbuffer = new StringBuffer ();
String restemp = "";
while ((restemp = Br.readline ()) = null) {
Resbuffer.append (restemp);
}
Responsestr = Resbuffer.tostring ();
Method.releaseconnection ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return responsestr;
}
}
Successful return value after request: {"MessageId": 107913122600012591, "Success": true, "Tips": "200successful"}
If there is no return, it indicates a failed send, possibly a problem with the session.
Java SMS Send Example 2