xusword
January 17th, 2007, 11:20 AM
The following code is supposed to execute a PostMethod and return the response stream.
I am having trouble getting respond body as a stream and return.
int connectionStatus;
try {
connectionStatus = client.executeMethod(post);
}
catch (Exception e){/*throw some exception*/}
InputStream result;
try{
result = post.getResponseBodyAsStream();
}
catch(IOException e){/*throw some exception*/}
finally{
post.releaseConnection();
}
if (connectionStatus == HttpStatus.SC_OK ){
return result;
}
else{/*throw some exception*/}
seems like if I release connection before returning the stream, the stream will be closed. If I do it after, the stream will be empty.
What should I do to get the stream or do I have to return byte array instead?
I am having trouble getting respond body as a stream and return.
int connectionStatus;
try {
connectionStatus = client.executeMethod(post);
}
catch (Exception e){/*throw some exception*/}
InputStream result;
try{
result = post.getResponseBodyAsStream();
}
catch(IOException e){/*throw some exception*/}
finally{
post.releaseConnection();
}
if (connectionStatus == HttpStatus.SC_OK ){
return result;
}
else{/*throw some exception*/}
seems like if I release connection before returning the stream, the stream will be closed. If I do it after, the stream will be empty.
What should I do to get the stream or do I have to return byte array instead?