Я делаю запрос на отправку по http одному из шлюзов xml, но согласно их правилу я должен отправить сообщение https post, вот мой код, и я получаю специальный код ошибки, который указывается в их руководстве что почтовый запрос должен быть https, можете ли вы помочь мне изменить следующий код.сделать https post request
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();
}
}
}
Итак, ваш вопрос заключается в том, как изменить запрос на 'https'? Просто измените свой 'strURL', чтобы начать с' https: // '... – Raptor
привет шиван! я попытался изменить http на https, теперь он не дает никакого вывода, он просто работает и работает. вы можете что-то предложить? –
Как я могу узнать без дополнительной информации? Вы также должны обратиться к поставщику API. – Raptor