dpnishant / appmon

Documentation:
http://dpnishant.github.io/appmon
Apache License 2.0
1.56k stars 276 forks source link

Can not get data from HTTPConnection again using HTTP.js #38

Open idoiwill opened 7 years ago

idoiwill commented 7 years ago

My target APP can not get data from HTTPConnction when I using HTTP.js. I debug the HTTP.js and find that the stream had been read before function getInputStream return. The APP get the result of getInputStream as stream and try to read the data using function read. But the read() return -1 cause the data had been read in HTTP.js.

If I return stream before the following code, my target APP will be fine: if (stream) { var BufferedReaderStream = BufferedReader.$new(InputStreamReader.$new(stream)); var inputLine = ""; while ((inputLine = BufferedReaderStream.readLine()) != null){ responseBody += inputLine + "\n"; } BufferedReaderStream.close();

I think we should copy a new stream and return. But I didn't find the way. Can you help me?

idoiwill commented 7 years ago

I wrote some codes to get the stream data.

var ByteArrayOutputStream =Java.use("java.io.ByteArrayOutputStream"); var ByteArrayInputStream = Java.use("java.io.ByteArrayInputStream"); var retval; if(stream){ var baos = ByteArrayOutputStream.$new(); var buffer = -1; while ((buffer =stream.read()) != -1){ baos.write(buffer); responseBody += String.fromCharCode(buffer); } baos.flush(); retval = byteArrayInputStream.$new(baos.toByteArray()); return retval;

I think this is an inefficient way to solve the problem.

dpnishant commented 6 years ago

@idoiwill Can you please kindly submit your script as a PR? Really sorry for responding so late.