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 ]