Syntes ikke helt jeg kan få det til at spille. Jeg har lige hurtig lavet en test med det her:
package postxml;
import java.io.*;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.HttpException;
public class PostXML{
public static void main(String[] args) throws HttpException, IOException {
String url = "
http://tralla.com/xmlservice/"; String body = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?><CAPSRequest CustomerID=\"XXX\"><ProductRequest><Language>ENU</Language><UnitSystem>UC_SI_Units</UnitSystem><Frequency>50</Frequency><ProductNumber>59504539</ProductNumber><QuotationTextWanted>true</QuotationTextWanted><CurveSetWanted>true</CurveSetWanted></ProductRequest></CAPSRequest> ";
String conttyp = "text/xml; charset=ISO-8859-1"; //"XML";
System.out.println(url);
System.out.println(body);
System.out.println(conttyp);
try {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url);
client.setConnectionTimeout(8000);
post.setRequestEntity(new StringRequestEntity(body, conttyp, "UTF-8"));
int result = client.executeMethod(post);
post.getResponseBodyAsString();
// Display status code
System.out.println("Response status code: " + result);
// Display response
System.out.println("Response body2: ");
System.out.println(post.getResponseBodyAsString());
post.releaseConnection();
}
catch (HttpException httpe) {
httpe.printStackTrace();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Jeg får følgende svar:
Response status code: 200
Response body2:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<CAPSResponse><CAPSOutput><Error>No XmlRequest data</Error></CAPSOutput></CAPSResponse>
Så jeg må gøre et eller andet galt mht. XML'en, for såvidt jeg ved betyder status code 200 "forbindelse ok" eller noget i den stil.