我成功调用了SAP Ariba Web服务。但是,响应包括一个zip文件,我无法弄清楚如何保存。以下是我调用Web服务的代码片段:
//Code to make a webservice HTTP request
URL url = new URL(strEndPoint);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection)connection;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
OutputStream out = null;
InputStreamReader isr = null;
BufferedReader in = null;
byte[] buffer = new byte[strXMLInput.length()];
buffer = strXMLInput.getBytes();
bout.write(buffer);
byte[] b = bout.toByteArray();
// Set the appropriate HTTP parameters.
httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
//Optional: set your action
//httpConn.setRequestProperty("SOAPAction", strEndPoint);
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
out = httpConn.getOutputStream();
// write the content of the request to the outputstream of the HTTP Connection.
out.write(b);
out.close();
// read the response.
isr = new InputStreamReader(httpConn.getInputStream());
in = new BufferedReader(isr);
// write the SOAP message response to a String.
while ((strResponse = in.readLine()) != null)
{
strResponseOut = strResponseOut + strResponse + "\n";
}
了解有关如何从java中的Web服务响应保存文件的任何指导。