Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending custom http headers through HttpClient

Status
Not open for further replies.

sharon3874

Programmer
Oct 27, 2006
24
US
I want to use Apache's HttpClient to send http request header. Can anyone take a look into my code and see if it is correct? (I am using msn's web site for testing purpose)

String url = "HttpClient client = new HttpClient();
GetMethod get = new GetMethod(url);

String etranAuthStr2 = "test";

get.setRequestHeader("CT_REMOTE_USER", "SXYANGET");
get.setRequestHeader("ETRANAUTH", etranAuthStr2);

client.executeMethod(get);

response.getWriter().print(get.getResponseBodyAsString().toString());

I use a debugging tool called "Fiddler" to see the request headers being sent, and looks like the headers are not sending over. did I miss anything? anyone has any idea?
 
Sorry I thought it didn't work, but actually I was wrong, the headers were sent.

I have another problem. the url I am sending my request to is the login page of another application (written in asp.net). I used " in my example just for testing purpose. When I sent the request to the login page, it redirected to the home page, but the images and styles were lost.

Anyone has thoughts? Thank you in advance for your help.
 
What I am doing is to have a link in my java in house application leads to a vendor application, which is written in asp.net.

As long as the user logs in to my java application and click on the link, the user does not need to login again.

So I need to send the user information through the http header to the vendor login page (vendor specific requirement).

I am able to log in now but the look and feel of the page (redirected from the login page) is not right (no images and styles).

Is it correct to use the following to display the content of the response? am I missing anything?

response.getWriter().print(get.getResponseBodyAsString().toString());

 
The style and images will reside in separate resource files and these are fetched by the browser in separate requests on the web server.

I'm somewhat rusty will all this, but you seem to be sending the redirected content to the client browser from your web context, and the resources referred to in this content will not be available in your web context.

I'm not sure what you should do about it, however. Maybe someone else could respond to sharon3874's query?

Tim
 
Thanks for your reply.

I think you are correct, but I have no solution.
 
You're acting as a kind of proxy, so you need to redirect the request (different than capture and issue a new one), be transparent.

Where's the content being displayed?

Cheers,
Dian
 
I had something like the following in my servlet:

response.setStatus(301);
response.setHeader("CT_REMOTE_USER", "SXYANGET");
response.setHeader("ETRANAUTH", "etranAuthStr2");
response.setHeader( "Location", " );
response.setHeader( "Connection", "close" );

I used "fiddler"(debugging tool) to check the http headers, but nothing was passed over.

the content is displayed inside a iframe of the java application.
 
I have a jsp, inside the jsp, I have a iframe, the source to the iframe is the servlet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top