[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Doing a POST
Unless you really want to/have to build this yourself, you may want to look
at something that has already been built.
I use cURL quite a lot but there is also wget.
http://curl.haxx.se/
http://www.wget.org/
At 11:22 AM 8/29/2003 -0400, Christopher Fowler wrote:
>Hello,
>
>I'm trying to replicate what a browser does when it connects
>to one of our sites. Here is what I've caught when Mozilla accessed
>the page:
>
>POST /auth.asp HTTP/1.1^M
>Connection: Keep-Alive^M
>User-Agent: Mozilla/5.0 (compatible; Konqueror/3.1; Linux)^M
>Referer: http://127.0.0.1/auth.asp^M
>Pragma: no-cache^M
>Cache-control: no-cache^M
>Accept: text/*, image/jpeg, image/png, image/*, */*^M
>Accept-Encoding: x-gzip, x-deflate, gzip, deflate, identity^M
>Accept-Charset: iso-8859-1, utf-8;q=0.5, *;q=0.5^M
>Accept-Language: en^M
>Host: 127.0.0.1^M
>Content-Type: application/x-www-form-urlencoded^M
>Content-Length: 45^M
>^M
>login=super&password=smart&action_login=Login------------------------------------------------------------
>
>
>I'm trying to replicate the post with the following java code
>
> try {
> URL url = new URL("http://127.0.0.1/auth.asp");
> HttpURLConnection connection =
> (HttpURLConnection)url.openConnection();
> connection.setRequestMethod("POST");
> connection.setRequestProperty("login", "super");
> connection.setRequestProperty("password", "smart");
> /*
> connection.setRequestProperty(
> "Authorization",
> "Basic " + "cm9vdDpwYXNzd29yZA=="
> );
> */
> BufferedReader br = new BufferedReader(new
> InputStreamReader(connection.getInputStream()));
> while((s = br.readLine()) != null) {
> System.out.println(s);
> }
> } catch (Exception Exp) {
> System.err.println("Error: " + Exp.getMessage());
> System.exit(1);
> }
>
>
>Can someone tell me what I'm doing wrong or what methods I should be
>using?
>
>Thanks,
>Chris