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?
 
CEHJCommented:
>>con.setRequestProperty("HTTP_USER_AGENT", "somthing");

should be

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

0
 
CEHJCommented:
And AFAIK the other should be

con.setRequestProperty("Referer", "http://www.somewhere.com");
0
 
hoomanvAuthor Commented:
surprising
tnx. worth an A
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
CEHJCommented:
hoomanv can you explain why my previous correct answers were ignored?
0
 
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.
0
 
hoomanvAuthor Commented:
oh my god
its my fault
i though you were the poster of the last comment
how can i correct it  ?
0
 
CEHJCommented:
OK - don't worry, i can get it reopened. You need do nothing until you get a notification
0
 
Mayank SAssociate Director - Product EngineeringCommented:
I have asked Venabili already.
0
 
CEHJCommented:
OK thanks m.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
No problem CEHJ ;-)
0
 
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();
    }
}



0
 
CEHJCommented:
We can help with that possibly - but not here as it's against the rules. Please post a new Q
0
 
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.
0
 
CEHJCommented:
:-)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Thanks, Nata for all the help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.