質問

I'm trying to use Clickatell's Connect API ( http://www.clickatell.com/downloads/Clickatell_Connect_API_User_Guide.pdf?cid=205655 ) in order to create users and send sms. Clickatell's API provides you with a specific URL that you have to submit a case-sensitive XML as an HTTPS form post.

I've written the following simple xml

<?xml version="1.0"?>
<CLICKATELLSDK>
<Action>get_list_country</Action>
</CLICKATELLSDK>

and I have used various code sample online (some taken from answer from stackoverflow, other from google searches - i.e. http://www.java-tips.org/other-api-tips/httpclient/how-to-send-an-xml-document-to-a-remote-web-server-using-http-5.html )on how to submit it as an HTTPS POST, but I always get the following responce.

<?xml version="1.0"?>
<CLICKATELLSDK>
<Result>Error</Result>
<Error>999</Error>
<Description>No XML Data found</Description>
<Timestamp>1353538744</Timestamp>
</CLICKATELLSDK>

Anyone using Clickatell's Connect API that can help me out or does anyone have any ideas?

役に立ちましたか?

解決

I managed to get it working using the following code

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
            }

    }

}

Let me know if you don't come right, so we can tackle it further!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top