今天系统加了 个 手机的api接口 ,后来发现是 接口编码问题!
public static int sendPhoneText(String phone,String content) throws Exception {
String contents = java.net.URLEncoder.encode(content,"gb2312");
if(content.length()>64){
return 0;
}
String companyID=Constants.SMS_COMPANYID;
String userName=Constants.SMS_USERNAME;
String userpwd=Constants.SMS_PWD;
String sendtime="";
String smsnumber=Constants.SMS_NUMBER;
URL url = new URL(
"http://api.***.com/sms/HttpInterface.aspx?comid="+companyID+"&username="+userName
+ "&userpwd="+userpwd+"&handtel="+phone+"&sendcontent="+contents
+ "&sendtime="+sendtime+"&smsnumber="+smsnumber);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(
httpCon.getInputStream()));
String line = in.readLine();
System.out.println("
result: " + line);int i_ret = httpCon.getResponseCode();
String sRet = httpCon.getResponseMessage();
System.out.println("sRet is: " + sRet);
System.out.println("i_ret is: " + i_ret);
return 0;
}
只要把 url 的 msgtext
String contents = java.net.URLEncoder.encode(content,"gb2312");//gbk 等。。