473,379 Members | 1,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 44317

<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
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
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
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
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
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
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
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.