By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,032 Members | 825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,032 IT Pros & Developers. It's quick & easy.

how to set an http request header used in HttpURLConnection ?

P: n/a
Is it possible for a Java network application, using HttpURLConnection, to
set or influence the setting of, http headers like Connection. One example
might be setting Connection: Close to indicate that this is the last
expected transaction for a while and the persistent connection can be closed
with the response.
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

<ma***@sbcglobal.net> wrote in message news:40**********@127.0.0.1...
Is it possible for a Java network application, using HttpURLConnection, to
set or influence the setting of, http headers like Connection. One example
might be setting Connection: Close to indicate that this is the last
expected transaction for a while and the persistent connection can be closed with the response.
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---

Look at setRequestProperty/addRequestProperty.

Silvio Bierman
Jul 17 '05 #2

P: n/a
Maby you want to look at this:
http://jakarta.apache.org/commons/httpclient/

On Mon, 17 May 2004 13:05:21 GMT, <ma***@sbcglobal.net> wrote:
Is it possible for a Java network application, using HttpURLConnection,
to
set or influence the setting of, http headers like Connection. One
example
might be setting Connection: Close to indicate that this is the last
expected transaction for a while and the persistent connection can be
closed
with the response.
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet
News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via
Encryption =---


--
// Daniel Jensen Aka. Daniboy
Da******@456believeit131hotmail.com
Jul 17 '05 #3

P: n/a
setRequestProperty will throw an Illegal State Exception - Already
connected. This is a persistent connection.
Jul 17 '05 #4

P: n/a
You trying to use that method af connection have been established?

On Wed, 19 May 2004 01:58:14 GMT, <ma***@sbcglobal.net> wrote:
setRequestProperty will throw an Illegal State Exception - Already
connected. This is a persistent connection.


--
// Daniel Jensen Aka. Daniboy
Da******@456believeit131hotmail.com
Jul 17 '05 #5

P: n/a
//proving http persistent connections - two test sequences.
//#1 Two requests with a permission to close on the second.
//#2 Two requests with no permission to close on the second - server
keep-alive (misnomer) timeout.

import java.net.*;
import java.io.*;
class Httppersist
{

public static void main(String[] args) throws Exception
{
URL url = null;
HttpURLConnection conn = null;
BufferedReader respContent = null;
PrintWriter display;
String respLine;
//request 1
url = new URL("http://CHCCW1.win.wellsfargo.com/gmTest/1a.txt");
conn = (HttpURLConnection) url.openConnection();
System.out.println("Test 1, req 1: response code = " +
conn.getResponseCode());
respContent = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
display = new PrintWriter(System.out);
while( (respLine = respContent.readLine()) != null)
{
display.println(respLine);
}
display.flush();
respContent.close();
conn.disconnect();

//request 2 with a Connection: close
url = new URL("http://CHCCW1.win.wellsfargo.com/gmTest/1b.txt");
conn.setRequestProperty("Connection", "Close"); // *** thows exception
***
conn = (HttpURLConnection) url.openConnection();
System.out.println("Test 1, req 2: response code = " +
conn.getResponseCode());
respContent = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
display = new PrintWriter(System.out);
while( (respLine = respContent.readLine()) != null)
{
display.println(respLine);
}

display.flush();
respContent.close();
conn.disconnect();
}

}
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.