This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes setrequestheader() - User-Agent - no good? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "setrequestheader() - User-Agent - no good?" Watch "setrequestheader() - User-Agent - no good?" New topic
Author

setrequestheader() - User-Agent - no good?

javalisa
Greenhorn

Joined: Jun 14, 2002
Posts: 7
I am unable to set the request header in my java program.
My little code snippet compiles and runs yet I don�t have a handle on whether setting a request header in a Java client before sending out the request to the server really does anything. Perhaps I have things out of order or am not addressing the correct layer of the connection.
At the end of this post is the code snippet that I started to work on. It compiles, runs but it is ineffective in setting the User-Agent.
I put up a tiny page on the server at
http://www.repcheck.com/javaLogin.php to see the server�s point of view and indeed when I run the Login.java program against that page my local system (Windows XP) doesn�t pay any attention to what I said about the user agent in my code before sending out the request. I see that when I try to get the page http://www.repcheck.com/index.php the PHP code sees the user agent as Java no matter what I say in my client code.
I wonder if this function really does anything, in an earlier version of Java it did not. It must be me, right?

The server-side code is simply (in PHP)

<?
$headers = getallheaders();
while (list ($header, $value) = each ($headers)) {
echo "$header: $value<br />\n";
}
?>
The code at http://www.repcheck.com/index.php is:
(The problem is that the server sees "Java" no matter how hard I try to fake a non-Java client.

<?
// First test the "accept header" to see if it claims wml support
if(strpos(strtoupper($HTTP_ACCEPT),"VND.WAP.WML") > 0) {
$browser_test="wml";
}
else {

// Now check the "user agent" against a list of known WML browsers

$browser=substr(trim($HTTP_USER_AGENT),0,4);
if( $browser=="Noki" ||
$browser=="Eric" ||
$browser=="R380" ||
$browser=="MOT-" ||
$browser=="UPG1" ||
$browser=="Jing" ||
$browser=="Acoo" ||
$browser=="Wapt" ||
$browser=="QWAP" ||
$browser=="m-cr" ||
$browser=="MC21" ||
$browser=="Your" ||
$browser=="YOUR" ||
$browser=="w@pS" ||
$browser=="Alca" ||
$browser=="wapw" ||
$browser=="Rain" ||
$browser=="Java" ||
$browser=="AUR " ||
$browser=="UP.B" ||
$browser=="WAPm" ||
$browser=="WinW" ||
$browser=="WapI" ||
$browser=="WAPJ" ||
$browser=="WapV" ||
$browser=="4thp" ||
$browser=="Waps" ||
$browser=="Mits" ||
$browser=="SIE-" ||
$browser=="Aptu" ||
$browser=="WmlS" ||
$browser=="Wapa") {
$browser_test="wml";
}
else {
$browser_test="html";
}
}

// Browser branching
if($browser_test=="wml") {
header("Location: [url=http://www.repcheck.com/wap/index.php");]http://www.repcheck.com/wap/index.php");[/url]
}
else {
?>

***The rest is simply the HTML of the home page*****
Here is the Java client code (messy, I just started on it):

[ June 14, 2002: Message edited by: javalisa ]
[ June 14, 2002: Message edited by: Thomas Paul ]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Hi Lisa,
We don't have too many rules at JavaRanch but one of our rules is that you must use your full name as your display name. (see http://www.javaranch.com/name.jsp )
Thanks!
And everyone please help Lisa. She is one of my students!!!


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setrequestheader() - User-Agent - no good?
 
Similar Threads
how to send session info from Applet to servlet?
HttpURLConection and ClassCastException
being stuck at readLine() when reading HTTP request
Problem HTTPSURLConnection for Siteminder authentictaion
"contype" userAgent in Httprequest