根据第三方接口发短信



package com.actions;



import java.io.IOException;
import java.io.UnsupportedEncodingException;


import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
public class TestNews2 {

 public void test() {
  try {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);       
      httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
      httpclient.getParams().setParameter("http.protocol.content-charset",HTTP.UTF_8); 
      httpclient.getParams().setParameter(HTTP.CONTENT_ENCODING, HTTP.UTF_8); 
      httpclient.getParams().setParameter(HTTP.CHARSET_PARAM,HTTP.UTF_8); 
      httpclient.getParams().setParameter(HTTP.DEFAULT_PROTOCOL_CHARSET,HTTP.UTF_8);
    HttpPost httppost = new HttpPost("http://dx.ipyy.net/sms.aspx?action=send&userid=&account=&password=&mobile=&content=大家好+【人寿】&sendTime=&extno=");
    HttpResponse response;
  response = httpclient.execute(httppost);
  String result=EntityUtils.toString(response.getEntity(),"utf8");
  } catch (UnsupportedEncodingException e) {
   
   e.printStackTrace();
  }
 catch (ClientProtocolException e) {
   
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
   
 }
}
 
 
 
 


你可能感兴趣的:(短信)