0

我正在尝试通过 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 发送短信的最佳方式是什么?

谢谢。

4

1 回答 1

0

您需要配置 kannel 才能使用post

用户组

 group = sms-service

替换 get-urlpost-url

您还需要以下仅适用于 Post 的参数

send-sender
strip-keyword   

在您的应用程序上,您还需要使用一些自定义标头Kannel POST

此标头可能包括

X-Kannel-From   Only sent if send-sender is true
X-Kannel-To  
X-Kannel-Time    
X-Kannel-UDH    in hex format: 06050415820000
X-Kannel-SMSC    
X-Kannel-MClass  
X-Kannel-PID     
X-Kannel-Alt-DCS     
X-Kannel-MWI     
X-Kannel-Coding 0=7 Bits, 1=8 Bits, 2=UCS-2
X-Kannel-Compress    
X-Kannel-Validity    
X-Kannel-Deferred    
X-Kannel-Service

请参阅文档http://www.kannel.org/download/1.4.3/userguide-1.4.3/userguide.htmlKannel Post了解其工作方式

于 2012-04-06T10:51:56.553 回答