你应该需要URL解码,我刚好也在做这个短信上行下行的接口,到时候我们可以讨论下 // beans.setMo_To(request.getParameter("Mo_To")); // beans.setMsg(URLDecoder.decode(request.getParameter("msg"), // "UTF-8")); // 解码 // beans.setMo_Msg(URLDecoder.decode(request.getParameter("Mo_Msg"), // "UTF-8")); // beans.setMobile(request.getParameter("mobile")); // // Date date = new Date(); // SimpleDateFormat format = new // SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // String mo_date = format.format(date); // beans.setMo_date(mo_date); // System.out.println(mo_date); // Pattern p = Pattern // .compile("^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$"); // // 手机格式 // Matcher m = p.matcher(beans.getMo_From()); // flag = m.matches(); // if (flag == true) { // Pattern pt = Pattern // .compile("^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$"); // // 手机格式 // Matcher mt = pt.matcher(beans.getMobile()); // res = mt.matches(); // if (res == true) { // tpMoDao.insertTpMoBeans(beans); // } else { // System.out.println("mobile手机号码格式不正确"); // } // } else { // System.out.println("上行手机号码格式不正确"); // }
这是关于HTTP传输协议,你把你带的参数在from表单获取是用 var no = document.getElementById("notice").value; no = encodeURI(no); no = encodeURI(no); 加密两次,到后台用notice = java.net.URLDecoder.decode(notice,"UTF-8"); 解密应该就OK了 如果对你有帮助,请给分
或者服务器那边只接受特定的一种编码格式。
我的tomcat 和eclipse 都是UTF-8 de ,短信接口也是UTF-8 , 但是我发送到手机上的时候
中文的就显示成? 了,英文和数字没有问题
我的tomcat 和eclipse 都是UTF-8 de ,短信接口也是UTF-8 , 但是我发送到手机上的时候
中文的就显示成? 了,英文和数字没有问题
都改成GBK的试一试,其它的都没问题的话,那么我们只能怀疑手机不是以UTF-8解析的bytes的,而是以GBK解析的了。
我的tomcat 和eclipse 都是UTF-8 de ,短信接口也是UTF-8 , 但是我发送到手机上的时候
中文的就显示成? 了,英文和数字没有问题
都改成GBK的试一试,其它的都没问题的话,那么我们只能怀疑手机不是以UTF-8解析的bytes的,而是以GBK解析的了。这个不现实啊, 短信接口明确要求UTF-8 的,那个手机接收的应该也没有错,应该还是我哪里写的不对,
action=send&userid=1111&account=1111&password=1111&mobile=1111&content=取消&sendTime=&checkcontent=1我直接用接口测试的没有表单,提交方式是post ,上面是串
action=send&userid=1111&account=1111&password=1111&mobile=1111&content=取消&sendTime=&checkcontent=1我直接用接口测试的没有表单,提交方式是post ,上面是串
这样就是get提交了 设置一下request的编码方式 request.setCharacterEncoding("utf-8");加上试试
action=send&userid=1111&account=1111&password=1111&mobile=1111&content=取消&sendTime=&checkcontent=1我直接用接口测试的没有表单,提交方式是post ,上面是串
这样就是get提交了 设置一下request的编码方式 request.setCharacterEncoding("utf-8");加上试试不是,这个是我自己写的串, 不是访问的,而且我有转成UTF-8
String send = SmsClientAccessTool.getInstance().doAccessHTTPPost(
"url",
"action=send&userid=111&account=1111&password=111&mobile=111&content=取消&sendTime=&checkcontent=1", "utf-8");
System.out.println(send);
}
你的接口在浏览器里测试是乱码吗?还有你是用什么方法调用的接口呢!我没看懂你可以参考下我调用url地址的方法,感觉你和我以前用的一个短信接口一个样呢?参数是一样的
public static void main(String[] args) {
try {
URL url=new URL("http://www.baidu.com/");
HttpURLConnection con=(HttpURLConnection)url.openConnection();
BufferedReader br=new BufferedReader(new InputStreamReader(url.openStream(),"utf-8"));
String line;
while((line=br.readLine())!=null)
{
System.out.println("提取:"+line);
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String send(String content)
{
String result="";
try {
URL url=new URL("http://www.baidu.com/send?account=qq&pwd=123&content="+content+"");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
这个就是调用发送的方法, 他这个方法需要三个参数,一个url ,一个是参数串也就是用户名密码内容什么的,另外一个就是返回值编码,我在发送的接口里面看还是正常的,发送到手机的时候中文就变成? 了,这个的意思就是调用发送的方法传参的时候还不是乱码的
2.看看接口说明, 一般都有例子的,没例子就自己研究吧,
3.中文传值的时候是否需要encodeURI和decodeURI这种转码
// beans.setMsg(URLDecoder.decode(request.getParameter("msg"),
// "UTF-8")); // 解码
// beans.setMo_Msg(URLDecoder.decode(request.getParameter("Mo_Msg"),
// "UTF-8"));
// beans.setMobile(request.getParameter("mobile"));
//
// Date date = new Date();
// SimpleDateFormat format = new
// SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// String mo_date = format.format(date);
// beans.setMo_date(mo_date);
// System.out.println(mo_date);
// Pattern p = Pattern
// .compile("^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$");
// // 手机格式
// Matcher m = p.matcher(beans.getMo_From());
// flag = m.matches();
// if (flag == true) {
// Pattern pt = Pattern
// .compile("^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$");
// // 手机格式
// Matcher mt = pt.matcher(beans.getMobile());
// res = mt.matches();
// if (res == true) {
// tpMoDao.insertTpMoBeans(beans);
// } else {
// System.out.println("mobile手机号码格式不正确");
// }
// } else {
// System.out.println("上行手机号码格式不正确");
// }
var no = document.getElementById("notice").value;
no = encodeURI(no);
no = encodeURI(no);
加密两次,到后台用notice = java.net.URLDecoder.decode(notice,"UTF-8"); 解密应该就OK了
如果对你有帮助,请给分