我正在尝试通过 Get 方法使用 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 方法发送它,我在其中设置了内容类型 = 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 发送短信的最佳方式是什么?
谢谢。