• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2145
  • Last Modified:

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
0
hoomanv
Asked:
hoomanv
  • 7
  • 6
  • 3
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now