(Java) HTTP Post XML
Demonstrates how to POST XML to a website. Note: This example requires Chilkat v11.0.0 or greater.
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
// Make sure to replace the URL with something real...
String url = "https://example.com/example.asp";
String xmlBody = "<test>This is the XML to be sent</test>";
CkHttpResponse resp = new CkHttpResponse();
success = http.HttpStr("POST",url,xmlBody,"utf-8","application/xml",resp);
if (success == false) {
System.out.println(http.lastErrorText());
return;
}
// Examine the body of the response.
System.out.println(resp.bodyStr());
}
}
|