Results 1 to 4 of 4
Thread: write http response into file?
- 10-09-2009, 11:38 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 5
- Rep Power
- 0
write http response into file?
Hi everybody,
I want to know how it's possible to write
a http responsen into a file.
I tried it a little, but I had a lot of conversion problem:
Here is the code:
thank you very much :)Java Code:import java.io.*; import java.net.*; public class Studium { public static void main(String[] args) throws IOException{ if(args.length == 0){throw new IllegalArgumentException("define host!");} OutputStream response = null; if (args.length == 2) response = new FileOutputStream(args[1]); else response = System.out; URL url = new URL(args[0]); String protocol = url.getProtocol(); if(!protocol.equals("http")){ throw new IllegalArgumentException("Please Enter the complete URL which includes protocol");} String host = url.getHost(); int port = 80; String[] Test={ "String1", "String2", "String3"}; try { for(int i = 0; i < Test.length; i++) { Socket socket = new Socket(host, port); InputStream input = socket.getInputStream(); OutputStream request = socket.getOutputStream(); String s = "GET /" + Test[i] + "\n"; request.write(s.getBytes()); request.flush(); byte[] buffer = new byte[4096]; int bytes; while((bytes = input.read(buffer)) != -1){ response.write(buffer, 0, bytes); } request.close(); input.close(); socket.close(); } } catch (IOException e) { e.printStackTrace(); } } }
- 10-10-2009, 06:47 PM #2
Member
- Join Date
- Oct 2009
- Posts
- 5
- Rep Power
- 0
or
If you have a clue how to get
the response statuscode with this code
and only a few modifications,
it would also solve my problem.
- 10-10-2009, 09:13 PM #3
Member
- Join Date
- Oct 2009
- Posts
- 5
- Rep Power
- 0
nenene dieses forum is mir zu schlecht.
ich komme nicht mehr hier ihr kotnascher.
- 10-10-2009, 11:21 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
Server returned HTTP response code: 500.. i need help
By hardc0d3r in forum Java ServletReplies: 9Last Post: 03-12-2012, 08:08 PM -
Getting information about HTTP response method
By Shiv in forum New To JavaReplies: 0Last Post: 04-10-2009, 07:58 PM -
HTTP response not read
By SD_Be in forum NetworkingReplies: 1Last Post: 03-10-2009, 04:36 PM -
Http Webserver - Mage inclution in response
By nlgopi in forum NetworkingReplies: 3Last Post: 10-18-2008, 03:17 PM -
Server returned HTTP response code: 500
By Heather in forum Java ServletReplies: 1Last Post: 07-09-2007, 04:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks