SMS Platform Interface Call method reference

Source: Internet
Author: User

HTTP request

Description: Refer to HttpClient, Httpcore, commons-logging three jar packages here

Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
Import java.util.*;
Import Java.security.MessageDigest;
Import org.apache.http.HttpEntity;
Import Org.apache.http.HttpResponse;
Import org.apache.http.client.HttpClient;
Import Org.apache.http.client.methods.HttpPost;
Import Org.apache.http.client.methods.HttpGet;
Import org.apache.http.client.entity.UrlEncodedFormEntity;
Import org.apache.http.impl.client.DefaultHttpClient;
Import Org.apache.http.message.BasicNameValuePair;
Import org.apache.http.*;
Import Javax.crypto.SecretKey;
Import Javax.crypto.spec.DESKeySpec;
Import Javax.crypto.spec.IvParameterSpec;
Import Javax.crypto.SecretKeyFactory;
Import Javax.crypto.Cipher;

public static void Main (string[] args) {
String url= "Http://xxx.com/api/MsgSend.asmx/SendMes";

list<namevaluepair> Nvps = new arraylist<namevaluepair> ();
Nvps.add (New Basicnamevaluepair ("Usercode", "User Name"));
Nvps.add (New Basicnamevaluepair ("Userpass", "password"));
Nvps.add (New Basicnamevaluepair ("Desno", "mobile phone Number"));
Nvps.add (New Basicnamevaluepair ("MSG", "SMS Content" signature ")");
Nvps.add (New Basicnamevaluepair ("channel", "aisle Number"));
String Post=httppost (URL,NVPS); POST request

String getparam= "usercode= user name &userpass= password &desno= mobile phone number &msg= SMS Content" signature "&channel= channel number";
String Result=httpget (Url,getparam); GET request
}

public static string HttpPost (string url,list<namevaluepair> params) {
String result = "";
try {
HttpClient HttpClient = new Defaulthttpclient ();
HttpPost HttpPost = new HttpPost (URL);
Httppost.setentity (New urlencodedformentity (params, "UTF-8"));
HttpResponse response = Httpclient.execute (HttpPost);
httpentity entity = response.getentity ();
if (Entity! = null) {
InputStream instreams = Entity.getcontent ();
result = Convertstreamtostring (instreams);
SYSTEM.OUT.PRINTLN (result);
}
} catch (Exception e) {
}
return result;
}

public static string HttpGet (string url,string params) {
String result= "";
try{
HttpClient client=new defaulthttpclient ();
if (params!= "") {
url=url+ "?" +params;
}
HttpGet httpget=new httpget (URL);
HttpResponse Response=client.execute (HttpGet);
Httpentity entity=response.getentity ();
if (Entity! = null) {
InputStream instreams = Entity.getcontent ();
result = Convertstreamtostring (instreams);
SYSTEM.OUT.PRINTLN (result);
}
}catch (Exception e) {}
return result;
}

public static String convertstreamtostring (InputStream is) {
BufferedReader reader = new BufferedReader (new InputStreamReader (IS));
StringBuilder sb = new StringBuilder ();

String line = null;
try {
while (line = Reader.readline ()) = null) {
Sb.append (line + "\ n");
}
} catch (IOException e) {
E.printstacktrace ();
} finally {
try {
Is.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
return sb.tostring ();
}

WebService request

public static void Main (string[] args) {
Org.tempuri.MsgSend service = new Org.tempuri.MsgSend ();
Org.tempuri.MsgSendSoap port = Service.getmsgsendsoap ();
String result= port.sendmes ("username", "password", "Phone number", "SMS Content" signature "", "channel number");
SYSTEM.OUT.PRINTLN (result);
}

SMS Platform Interface Call method reference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.