我正在尝试使用Clickatell的Connect API ( http://www.clickatell.com/downloads/Clickatell_Connect_API_User_Guide.pdf?cid=205655 )来创建用户和发送短信。Clickatell的API为您提供了一个特定的URL,您必须将区分大小写的XML作为HTTPS表单post提交。
我已经编写了以下简单的xml
<?xml version="1.0"?>
<CLICKATELLSDK>
<Action>get_list_country</Action>
</CLICKATELLSDK>我在网上使用了不同的代码样本(一些来自stackoverflow的答案,其他来自谷歌搜索-例如http://www.java-tips.org/other-api-tips/httpclient/how-to-send-an-xml-document-to-a-remote-web-server-using-http-5.html ),关于如何将其作为HTTPS POST提交,但我总是得到以下响应。
<?xml version="1.0"?>
<CLICKATELLSDK>
<Result>Error</Result>
<Error>999</Error>
<Description>No XML Data found</Description>
<Timestamp>1353538744</Timestamp>
</CLICKATELLSDK>有没有人使用Clickatell的Connect API来帮助我,或者有什么想法?
发布于 2012-11-23 20:38:08
我设法使用下面的代码让它正常工作
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpPost {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String postUrl = "https://connect.clickatell.com/[AuthenticationToken]";
try {
String tStatus = "";
URL url = new URL(postUrl + "&XML=<clickatellsdk><action>get_list_country</action></clickatellsdk>");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line = br.readLine()) != null)
{
tStatus = line;
System.out.println(tStatus);
}
} catch (Exception e)
{
//Handle Exception
}
}
}如果你不正确,请告诉我,这样我们就可以进一步解决它!
https://stackoverflow.com/questions/13519476
复制相似问题