473,506 Members | 17,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to set an http request header used in HttpURLConnection ?

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
5 44334

<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
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
setRequestProperty will throw an Illegal State Exception - Already
connected. This is a persistent connection.
Jul 17 '05 #4
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
//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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1225
by: boohoo | last post by:
Let's say I want to use the msxml object to call a web page from within my script, and on the querystring or "in the header" of that request I want to include a dictionary object, such that the...
2
7201
by: Mak | last post by:
Hi Everybody, I try set the Expect: 100-continue in my request to server. The way I do it is by setting : <META http-equiv="Expect" content="100-continue"> in my html page. But, it does not...
7
7709
by: mike | last post by:
regards: Does each HTTP Request have "Host:" header? Any positive suggestion is welcome. thank you May goodness be with you all
4
1763
by: mike | last post by:
regards: Is it possible to get the next hyperlink location in "EACH HTTP REQUEST HEADER?" Or, --------------------------------------------------------------------------- Does the following...
1
11020
by: mrbog | last post by:
Hello, I'm making HTTP requests with System.Net.HTTPWebRequest and I want to capture the entire header of the request as a string. I'm able to do this with responses but now the requests. Am I...
6
6081
by: Dave Slinn | last post by:
I have a VB app hosting the Webbrowser control. I would like to add "something" to the requests that app is submitted to our web application to indicate that its from this webbrowser and not a...
1
3120
by: Shashank | last post by:
Hi all, I am a new member of this community. I am making a http request to a html file placed on a Apache server. On this page there is an embeded perl statement which requires reading ...
5
14086
by: dabei | last post by:
Hi, I am trying to use AS3 to make a URL request with authorization header. Using the code below: var request:URLRequest = new URLRequest ( 'http://myserviceURL' ); var...
1
2247
by: campos | last post by:
Hi all, I am trying to use javascript to send an HTTP/post request to a server multiple times continously. But the time used on the 1st and 2nd files are longer than others. My idea is that...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.