0
我想通过Get方法使用HTTP客户端向Kannel发送短信: - 我不想编码它;因为@字符无法正确发送。如何使用HTTP客户端将@字符发送给Kannel?
如果我没有编码发送,我得到空间字符的错误。 的代码如下:
StringBuffer directives=new StringBuffer();
HttpClient client = new DefaultHttpClient();
directives.append("username=" + username);
directives.append("&password=" + password);
directives.append("&from=" + from);
directives.append("&to=" + to);
directives.append("&coding=0");
// Without Encoding
directives.append("&text=" + text);
directives.append("&smsc=" + smsc);
directives.append("&dlr-mask=" + dlrmask);
directives.append("&dlr-url=" + dlrurl);
URI uri = URIUtils.createURI("http", host, Integer.parseInt(port), "/cgi-bin/sendsms", directives.toString(), null);
HttpGet httpget = new HttpGet(uri);
HttpResponse httpResponse = client.execute(httpget);
我试图使用它的POST方法,其中,I设置内容类型= text/plain的发送: - Kannel的未接受所述参数
以下是代码:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://" + host + ":" + port + "/cgi-bin/sendsms");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
nameValuePairs.add(new BasicNameValuePair("from", from));
nameValuePairs.add(new BasicNameValuePair("to",to));
nameValuePairs.add(new BasicNameValuePair("text",text));
nameValuePairs.add(new BasicNameValuePair("smsc", smsc));
nameValuePairs.add(new BasicNameValuePair("dlr-mask",dlrmask));
nameValuePairs.add(new BasicNameValuePair("dlr-url",dlrurl));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = client.execute(post);
那么什么是最好的方式发送短信到kannel?
谢谢。
你有没有尝试添加“charset = ...”参数与您通过HTTP发送的字符串字符集?例如“&charset = utf-8”。 – 2012-04-03 06:28:57
我尝试过使用“&charset = utf-8”。它不工作。它给空间字符的错误。 – varsha 2012-04-03 06:45:55
“text”参数必须是URL编码的,空格应该表示为“+”或“%20”。 – 2012-04-03 08:09:03