Quantcast

Jump to content


Photo

Possible referer issue, not sure though?

java

  • Please log in to reply
3 replies to this topic

#1 Riku

Riku
  • 72 posts


Users Awards

Posted 01 October 2014 - 09:23 AM

Alright, so I'm working on a money tree grabber to refresh myself on Java. Whenever the program tries to grab something from the tree, the page returned is that "You have been directed here from the wrong place" error message, leading me to think the referer isn't being set correctly, since I can manually grab things without any problems.

 

I checked all the logical things first, just as the program correctly parsing the individual URLs, etc., but it's all fine.

 

Code in the program to grab the item (whose URL is stored in donationurls at index j), and the relevant wrapper code:

wrapper.setReferer("/donations.phtml");
strHTML = wrapper.get("/takedonation_new.phtml?donation_id=" + donationurls[j]);
  public String setReferer( String domain ) {
      referer = domain;
      return null;
  }
  public String get( String url ) {
    if( url.charAt( 0 ) == '/' )
      url = domain + url;
    
    try {
      HttpURLConnection conn = (HttpURLConnection)( new URL( url.replaceAll( " ", "%20" ) ).openConnection() );
      setRequestProperties( conn );
      conn.setRequestMethod( "GET" );
      referer = url;
      return read( conn );
    } catch( IOException e1 ) {
      e1.printStackTrace();
      return null;
    }
  }
  private void setRequestProperties( HttpURLConnection conn ) {
    ...
    
    if( referer != null && referer.length() != 0 )
      conn.setRequestProperty( "Referer", referer );
    
   ...
  }

I seriously have no idea what's wrong. I've been stuck at this stage for a day and nothing I do is working. Frustrating, to say the least.



#2 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 01 October 2014 - 09:42 AM

Have you tried setting the referrer to the fully qualified URL, including the domain?

 

e.g. 

http://www.neopets.com/donations.phtml


#3 Riku

Riku
  • 72 posts


Users Awards

Posted 01 October 2014 - 10:06 AM

Ohhhh my god, I cannot believe I overlooked that. I'm going to go cry for a few hours.



#4 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 01 October 2014 - 10:09 AM

;) Just here to save the day.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users