需要的jar包
commons-logging-1.1.1.jar
commons-httpclient-3.1.jar
commons-codec-1.4.jar
public static void main(String[] args)throws Exception
{
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn");
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在头文件中设置转码
//这里的参数在sms(中国建网)api那里有
NameValuePair[] data ={ new NameValuePair("Uid", "sms注册的用户账号"),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("gbk"));
System.out.println(result); //打印返回消息状态
post.releaseConnection();
}
成功显示1