import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.io.*;
public class AnveoAPI {
private static final String ANVEO_API_URL = "https://www.anveo.com/api/v2.asp";
private static final String XML = "<?xml version=\"1.0\"?>" +
"<REQUEST>" +
"<USERTOKEN>" +
"<USERKEY>ssssdf141891e2e883904b0b294dc5bq79c1c1c13f6d</USERKEY>" +
"</USERTOKEN>" +
"<ACTION NAME=\"DIAL.CONNECT\">" +
"<PARAMETER NAME=\"TEST\">TRUE</PARAMETER>" +
"<PARAMETER NAME=\"PHONENUMBER\">1215215215</PARAMETER>" +
"<PARAMETER NAME=\"DESTPHONENUMBER\">1212121212</PARAMETER>" +
"<PARAMETER NAME=\"CALLERID\">12157010680</PARAMETER>" +
"<PARAMETER NAME=\"DELAY\">1440</PARAMETER>" +
"<PARAMETER NAME=\"MEMO\">DIAL.CONNECT API Action example to connect 1215215215 with 1212121212 delayed by 24 hours</PARAMETER>" +
"</ACTION>" +
"</REQUEST>";
public static void main(String[] args) {
String xml = doApiCall();
// xml holds API result XML text
System.out.println(xml);
// parse XML Results with parser
// ...
}
private static String doApiCall() {
String result = null;
try {
URL url = new URL(ANVEO_API_URL);
URLConnection uc = url.openConnection();
HttpURLConnection connection = (HttpURLConnection) uc;
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.addRequestProperty("Content-Type", "application/xml; charset=UTF-8");
connection.addRequestProperty("Accept", "application/xml; charset=UTF-8");
OutputStream out = connection.getOutputStream();
Writer writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
writer.write(XML);
writer.flush();
writer.close();
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
StringBuffer sb = new StringBuffer();
String line;
while ((line = reader.readLine()) != null) sb.append(line);
reader.close();
connection.disconnect();
result = sb.toString();
} catch (IOException e) {
e.printStackTrace(); // ERROR loading XML
}
return result;
}
}