Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

setrequestheader() - User-Agent - no good?  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!