spoof HTTP_REFERER, HTTP_USER_AGENT

I want to make an HTTP connection and just change the HTTP_REFERER and HTTP_USER_AGENT
here is my code
   URLConnection con = url.openConnection();
   con.setRequestProperty("HTTP_REFERER", "http://www.somewhere.com");
   con.setRequestProperty("HTTP_USER_AGENT", "somthing");
but it doesn't work properly in real world
you can check it with a site like this to see the http request's properties
   URL url = new URL("http://www.inet-police.com/cgi-bin/env.cgi");
and
HTTP_USER_AGENT is always "Java/1.5.0_01"
and no referer is set
LVL 14
hoomanvAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>con.setRequestProperty("HTTP_USER_AGENT", "somthing");

should be

con.setRequestProperty("User-Agent", "somthing");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
And AFAIK the other should be

con.setRequestProperty("Referer", "http://www.somewhere.com");
hoomanvAuthor Commented:
surprising
tnx. worth an A
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

CEHJCommented:
hoomanv can you explain why my previous correct answers were ignored?
Mayank SAssociate Director - Product EngineeringCommented:
Yes, if it were more than 20 points, it could have been a split. Since it is not so, the first correct answer deserves the points.
hoomanvAuthor Commented:
oh my god
its my fault
i though you were the poster of the last comment
how can i correct it  ?
CEHJCommented:
OK - don't worry, i can get it reopened. You need do nothing until you get a notification
Mayank SAssociate Director - Product EngineeringCommented:
I have asked Venabili already.
CEHJCommented:
OK thanks m.
Mayank SAssociate Director - Product EngineeringCommented:
No problem CEHJ ;-)
hoomanvAuthor Commented:
before giving the points. i'll give more points if you solve this too
there is a poll form on the web that posts data to an ASP page
I created a html file localy and i am able to post form data just like this

<form name="frm" method="post" action="the url">
    <input type="hidden" name="voteChoice" value="498">
    <input type="hidden" name="PID" value="108">
    <input type="hidden" name="TID" value="7714">
    <input type="hidden" name="FID" value="33">
    <input type="hidden" name="PN" value="0">
    <input type="hidden" name="TPN" value="1">
    <input type="submit" name="Submit" value="Submit">
</form>

when I want to do this via java with the below code its not successfull to update the poll. i dont know why ?

import java.net.*;
import java.io.*;
import java.util.*;

public class PostForm {
    public static void main(String[] args) throws Exception {
        URL url = new URL("the url");
        String argString = "voteChoice=498&PID=108&TID=7714&FID=33&PN=0&TPN=1";
       
        argString = "voteChoice=498&PID=108&TID=7714&FID=33&PN=0&TPN=1";
       
        URLConnection con = url.openConnection();
        con.setDoInput(true);
        con.setDoOutput(true);
        con.setUseCaches(false);
        con.setRequestProperty("Referer", "http://www.google.com");
        con.setRequestProperty("User-Agent", "Mozilla/5.0");
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
       
        // Write the arguments as post data
        OutputStream out = con.getOutputStream();
        out.write(argString.getBytes());
        out.flush();
        out.close();
       
        // Read the response
        InputStream is = con.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = null;
        while((line = br.readLine()) != null) {
            System.out.println(line);
        }
        br.close();
    }
}



CEHJCommented:
We can help with that possibly - but not here as it's against the rules. Please post a new Q
Mayank SAssociate Director - Product EngineeringCommented:
hoomanv, that is a different question :) this one was already closed and was opened for a different reason - not because the question was unsolved. Please ask it in another thread.
CEHJCommented:
:-)
Mayank SAssociate Director - Product EngineeringCommented:
Thanks, Nata for all the help :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.