我正在向其中一个 xml 网关发出 http 发布请求,但根据他们的规则,我必须发布 https 发布请求,这是我的代码,我收到一个自定义错误代码,在他们的手册中表明发布请求必须是 https ,你能帮我修改下面的代码吗?
public class PostXML {
public static void main(String args[]) throws FileNotFoundException {
// Get target URL
String strURL = "http://xmlgw.companieshouse.gov.uk/v1-0/xmlgw/Gateway" ;
// Get file to be posted
String strXMLFilename = "F:\\12-8\\CompanyFormation\\CompanyFormation\\web\\file.xml";
File input = new File(strXMLFilename);
// Prepare HTTP post
PostMethod post = new PostMethod(strURL);
// Request content will be retrieved directly
// from the input stream
// Per default, the request content needs to be buffered
// in order to determine its length.
// Request body buffering can be avoided when
// content length is explicitly specified
post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(input), input.length()));
// Specify content type and encoding
// If content encoding is not explicitly specified
// ISO-8859-1 is assumed
post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
// Get HTTP client
HttpClient httpclient = new HttpClient();
// Execute request
try {
int result = httpclient.executeMethod(post);
// Display status code
System.out.println("Response status code: " + result);
// Display response
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
} catch (Exception e) {
e.printStackTrace();
} finally {
// Release current connection to the connection pool
// once you are done
post.releaseConnection();
}
}
}