Quantcast

Jump to content


Photo

Can someone help me with java post requests?


  • Please log in to reply
24 replies to this topic

#1 Nemecek

Nemecek
  • 52 posts

Posted 10 November 2013 - 11:11 PM

I'm trying to create a java program that logs me into neopets. but I'm running into some problems. is anyone here familiar enough with java to be of some help?



#2 Neoquest

Neoquest
  • 1760 posts


Users Awards

Posted 10 November 2013 - 11:24 PM

Got any code so far?

 

If it's just a basic POST request I'd suggest checking out stackoverflow, as this has surely been asked before. :)



#3 Nemecek

Nemecek
  • 52 posts

Posted 10 November 2013 - 11:45 PM

yes so this is my code below, it compiles and runs, but when I print out page source code I would expect it to print my logged on page source but it prints the standard neopets home page source code.
 
 
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
 
public class Login {
  public static void main(String[] args) {
 
    try {
 
      String destination = "%2F";
      String username = "myuser";
      String password = "mypass";
      String submit = "Log In!";
      
      String destination_param = "destination";
      String username_param = "username";
      String password_param = "password";
      String submit_param = "submit";
     
      String encoded_destination = destination_param + "=" + URLEncoder.encode(destination, "UTF-8");
      String encoded_username = username_param + "=" + URLEncoder.encode(username, "UTF-8"); 
      String encoded_password = password_param + "=" + URLEncoder.encode(password, "UTF-8");
      String encoded_submit = submit_param + "=" + URLEncoder.encode(submit, "UTF-8");
      
      String encoded = encoded_destination + "&" + encoded_username + "&" + encoded_password + "&" + encoded_submit;
 
        URL requestUrl = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) requestUrl.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestMethod("POST");
 
        DataOutputStream osw = new DataOutputStream(conn.getOutputStream());
        osw.writeBytes(encoded);
        osw.flush();
 
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
 
        String in = "";
 
        while ((in = br.readLine()) != null) {
          System.out.println(in);   
        }
 
        osw.close();
        br.close();
        
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}

Here is neopets login form:

 

<form method="post" action="/login.phtml">   <input type="hidden" id="templateLoginDest" name="destination" value="%2F">   <table style="width: 350px;" align="center">   <tr>   <td valign="top" width="100px"><b>Username:</b></td>   <td valign="top"><input type="text" name="username" id="templateLoginPopupUsername" size="30"></td>   </tr>   <tr>   <td valign="top"><b>Password:</b></td>   <td valign="top"><input type="password" name="password" size="30"><br><a href="/account/passwordreset.phtml" style="font-size: 8pt;">Forgot Password?</a><br><br></td>   </tr>   <tr>   <td colspan="2" align="center"><input type="submit" value="Log In!"></td>   </tr>   </table>   </form>

Edited by Nemecek, 10 November 2013 - 11:44 PM.


#4 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 11 November 2013 - 08:40 AM

Does HttpURLConnection handle cookies? If not you'll need to use a cookie manager otherwise you're always going to be logged out.



#5 Nemecek

Nemecek
  • 52 posts

Posted 11 November 2013 - 02:11 PM

I haven't looked into cookies yet. That's probably the way to do it but I'm wondering could I just resend my username and password each time I request a new page?



#6 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 12 November 2013 - 08:47 AM

I haven't looked into cookies yet. That's probably the way to do it but I'm wondering could I just resend my username and password each time I request a new page?

 

Nope. You might find some ideas on cookie handling in our old Java code snippets section:

 

http://www.neocodex....forum/137-java/



#7 Nemecek

Nemecek
  • 52 posts

Posted 12 November 2013 - 12:55 PM

Nope. You might find some ideas on cookie handling in our old Java code snippets section:

 

http://www.neocodex....forum/137-java/

I didn't know we had a java forum. Thank you!



#8 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 12 November 2013 - 01:18 PM

I didn't know we had a java forum. Thank you!

 

It's really just an archive, it's not visible on the forum index so there's no point in posting in there.



#9 Nemecek

Nemecek
  • 52 posts

Posted 17 November 2013 - 09:16 PM

I feel as though I've made a lot of progress. But now again I'm stuck. Here's a portion of my http wrapper

 

   http.connect();
      String charset = http.getContentType();
      InputStream receiving = null;
      
      //Parses the content type
      String[] content = new String[2];
      content = charset.split(";");
      content[1] = content[1].trim().toLowerCase();
      charset = content[1].substring("charset=".length());
      
      System.out.println(charset);
      
      if (charset.equals("gzip"))
        receiving = new GZIPInputStream(http.getInputStream());
      else if (charset.equals("deflate"))
        receiving = new InflaterInputStream(http.getInputStream(), new Inflater(true));
      /*else if (charset.equals("iso-8859-1")){
       // receiving = ???
      }*/
 
now instead of getting what i thought was the usual charsets (gzip and deflate) it returns to me charset=iso-8859-1. Is this normal? and if so how do I handle it? I've done some research but didn't really come up with anything useful. 


#10 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 18 November 2013 - 08:39 AM

http://ubuntuforums....ad.php?t=833993

 

Perhaps that will help?



#11 Nemecek

Nemecek
  • 52 posts

Posted 30 November 2013 - 12:29 AM

Here's another update:

 

I send my form data which looks something like this: destination=%252Findex.phtml&username=user&password=pass

 

I create and send headers with all the information Google Chrome shows me its sending (with the exception of the cookies)

 

  1. Host:
    www.neopets.com
  2. Origin:
  3. Referer:
  4. User-Agent:
    Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
  1. Accept:
    text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  2. Accept-Encoding:
    gzip,deflate,sdch
  3. Accept-Language:
    en-US,en;q=0.8
  4. Cache-Control:
    max-age=0
  5. Connection:
    keep-alive
  6. Content-Length:
    69
  7. Content-Type:
    application/x-www-form-urlencoded
  8. Cookie: Cookies (This part I'm not sure about because although Google Chrome sends neopets a shit ton of cookies I don't send anything because it has nothing to do with my account it's just information regarding where I live and stuff)

 

 

 

 

 

 

Then my program outputs these as the Response headers:

 

Response Headers:--
null: HTTP/1.1 200 OK
Date: Sat, 30 Nov 2013 07:45:04 GMT
Server: Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7a PHP/5.1.6
X-Powered-By: PHP/5.1.6
Set-Cookie: np_randseed=xxxxxxxxxxxxxxxxxxxxxxx; expires=Sun, 30-Nov-2014 07:45:04 GMT; path=/; domain=.neopets.com
X-XSS-Protection: 0
Set-Cookie: np_uniq=pending; expires=Sun, 30-Nov-2014 07:45:04 GMT; path=/; domain=.neopets.com
Set-Cookie: xt6Yr4e33D=xxxxxxxxxxxxxxxxxxxxxxxxxx; expires=Sun, 30-Nov-2014 07:45:04 GMT; path=/; domain=.neopets.com
Vary: Accept-Encoding,User-Agent
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
 
When Google Chrome clearly shows me I should be receiving:
 
  1. Cache-Control:
    no-cache, must-revalidate
  2. Connection:
    close
  3. Content-Encoding:
    gzip
  4. Content-Length:
    20
  5. Content-Type:
    text/html; charset=UTF-8
  6. Date:
    Sat, 30 Nov 2013 06:46:06 GMT
  7. Expires:
    Mon, 26 Jul 1997 05:00:00 GMT
  8. Last-Modified:
    Sat, 30 Nov 2013 06:46:06 GMT
  9. Location:
    /index.phtml
  10. p3p:
  11. Pragma:
    no-cache
  12. Server:
    Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7a PHP/5.1.6
  13. Set-Cookie:
    ssotoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; expires=Sun, 30-Nov-2014 06:46:06 GMT; path=/; domain=.neopets.com
  14. Set-Cookie:
    neoremember=myusername; expires=Sun, 02-Mar-2014 20:59:26 GMT; path=/; domain=.neopets.com
  15. Set-Cookie:
    wc_ids=0; expires=Thu, 29-Aug-2013 16:32:46 GMT; path=/; domain=.neopets.com
  16. Set-Cookie:
    neologin=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; expires=Sun, 30-Nov-2014 06:46:06 GMT; path=/; domain=.neopets.com
  17. Set-Cookie:
    toolbar=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; expires=Sun, 30-Nov-2014 06:46:06 GMT; path=/; domain=.neopets.com
  18. Vary:
    Accept-Encoding,User-Agent
  19. X-Powered-By:
    PHP/5.1.6
 
I'm a little discouraged I'm not sure where to go from here, can anyone look through/ try my code and tell me where I'm going wrong?
 
 
 
Here's The main code that send the form data to my httpwrapper
 
import java.io.*;
import java.net.URLEncoder;
import javax.swing.JOptionPane;
 
public class Main{
  
  private static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
  private String userpost;//Postdata for the username on Step 1.
  private String passpost;//Postdata for the username and password on Step 2.
  String sHTML = "";
  
  public static void main(String[] args) throws IOException {        
    
    Main run = new Main();
    run.NPLogin();   
  }
  
  public void NPLogin() throws IOException {
    
    HTTPWrapper wrapper = new HTTPWrapper();
    String url = "www.neopets.com/login.phtml";
    String destination = "%2Findex.phtml";
    String username = JOptionPane.showInputDialog(null, "Enter your username");
    String password = JOptionPane.showInputDialog(null, "Enter your password");
    
    String destination_param = "destination";
    String username_param = "username";
    String password_param = "password";
    
    
    String encoded_destination = URLEncoder.encode(destination_param, "UTF-8") + "=" + URLEncoder.encode(destination, "UTF-8");
    String encoded_username = URLEncoder.encode(username_param, "UTF-8") + "=" + URLEncoder.encode(username, "UTF-8"); 
    String encoded_password = URLEncoder.encode(password_param, "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8");
    
    String encoded = encoded_destination + "&" + encoded_username + "&" + encoded_password;
    
    System.out.println("Form Data: " + encoded);
    
    sHTML = wrapper.Request(url, encoded, "http://www.neopets.com/index.phtml");
    
    if(sHTML.contains(username)){ //If the page source code contains my username the connection will have worked.
      System.out.println("Login Sucessful.");
    }
    else {
      System.out.println("Login Failed.");
    }
  }
}
 
And here's my http wrapper
 
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import java.nio.charset.Charset;
import java.io.InputStreamReader;
 
import java.io.IOException;
import java.net.UnknownHostException;
 
public class HTTPWrapper {
  
  public static String strCookies;
  private static String strHTML;
  
  public static String Request(String urlstr, String postData, String referer) {
    
    String method; 
    
    if(postData != "") 
      method = "POST"; 
    else method = "GET";
    
    if(strCookies == null) {
      strCookies = """;
    }
    
    try{
      URL url = new URL("http://" + urlstr);
      
      HttpURLConnection http = (HttpURLConnection)(url.openConnection());
      http.setFollowRedirects(true);
      
      http.setRequestMethod(method); //Sets the request Method (POST or GET)
     
      //Sets Headers
      http.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
      http.setRequestProperty("Accept-Encoding", "gzip,deflate,sdch");
      http.setRequestProperty("Accept-Language", "en-US,en;q=0.8");
      http.setRequestProperty("Cache-Control", "max-age=0");
      http.setRequestProperty("Connection", "keep-alive");
      http.setRequestProperty("Host", "www.neopets.com");
      http.setRequestProperty("Origin", "http://www.neopets.com");
      http.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36");
 
      if (referer != "0")
        http.setRequestProperty("Referer", referer);
 
      if (strCookies != "")
        http.setRequestProperty("Cookie:", strCookies);
      
      if (method == "POST") {
 
        http.setDoOutput(true); 
        http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        http.setRequestProperty("Content-Length", "" + postData.length());
 
        OutputStreamWriter writePost = new OutputStreamWriter(http.getOutputStream());
        
        writePost.write(postData);
        writePost.flush();
      }
      
      http.connect();
      String charset = http.getContentType();
      InputStream receiving = null;
      
      //Parses the content type
      String[] content = new String[2];
      content = charset.split(";");
      content[1] = content[1].trim().toLowerCase();
      charset = content[1].substring("charset=".length());
      
      System.out.println("Charset Type: " + charset + "\n");
      
      if (charset.equals("gzip"))
        receiving = new GZIPInputStream(http.getInputStream());
      else if (charset.equals("deflate"))
        receiving = new InflaterInputStream(http.getInputStream(), new Inflater(true));
      else if (charset.equals("utf-8")){
        receiving = http.getInputStream();
      }
      else{
        receiving = http.getErrorStream();
      }
      
      int intReceived;
      StringBuffer strBuffer = new StringBuffer();
      
      while((intReceived = receiving.read()) != -1) {
        strBuffer.append((char) intReceived);
      }
      
      receiving.close();
      strHTML = strBuffer.toString();
      strBuffer.delete(0, strBuffer.length()); strBuffer.append(strCookies);
     
      if (strCookies.length() > 3) 
        strBuffer.append("; ");
      
      
      System.out.println("Response Headers:--");
      for (int i=0; ; i++) {
        
        if (http.getHeaderFieldKey(i) == null && http.getHeaderField(i) == null) {
          break;
        }
        else if ("Set-Cookie".equalsIgnoreCase(http.getHeaderFieldKey(i))) {
          String[] fields = http.getHeaderField(i).split(";\\s*");
          String[] keyvalue = fields[0].split("=");
          if (strBuffer.indexOf(keyvalue[0] + "=") == -1)
            strBuffer.append(keyvalue[0] + "=" + keyvalue[1] + "; ");
          else
            strBuffer.replace(strBuffer.indexOf(keyvalue[0]), strBuffer.indexOf(";", strBuffer.indexOf(keyvalue[0])), keyvalue[0] + "=" + keyvalue[1]);
        }
        System.out.println(http.getHeaderFieldKey(i) + ": " + http.getHeaderField(i));
      }
      if (strBuffer.indexOf("; ", strBuffer.length() - 3) != -1)
        strBuffer.delete(strBuffer.length() - 2, strBuffer.length());
      strCookies = strBuffer.toString();
    } catch (Exception e) {System.out.println(e);}
    
    
    System.out.println(strHTML);
    System.out.println("");
    System.out.println("Cookies; " + strCookies);
    return strHTML;
  }
}

Edited by Nemecek, 30 November 2013 - 12:32 AM.


#12 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 30 November 2013 - 02:41 AM

Compare the headers you're sending side-by-side with the headers a browser sends when logging in and make sure they're substantially the same (especially the page where the data is being sent to and the data itself).



#13 Nemecek

Nemecek
  • 52 posts

Posted 30 November 2013 - 01:20 PM

Waser Lave Thank you for helping me out and being so quick to answer all the time. 

 

However my headers are identical. The data being sent is identical and it is being sent to the right location. Other possible errors I thought of were:

 

-The order of the headers? Although I thought this didn't matter.

-The cookie header: My browser sends some cookies but my program only sends an empty string. Once the program logs in it stores the response cookies and would send that along with my future posts. I've tried copy pasting my cookies and sending that with my log in post but that failed as well.

-At the beginning of the post it says: "POST /login.phtml HTTP/1.1 " Do I have to do anything with the HTTP/1.1?

-The reason I believe I'm not logging in is because the page source code I get does not contain my username. Maybe I'm getting the wrong page source? I say this because when I put in my real name and password I get the neopets main page source code but when i type a invalid user and pass I get a bad password page.

 

I feel like I'm really close. I just need a little push! 



#14 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 30 November 2013 - 01:23 PM

The order doesn't really matter too much, it shouldn't really matter if you send empty cookies to start with and you can ignore the HTTP/1.1 thing.

 

If it doesn't have your username what does the page source show? Try outputting the html and creating a html file and have a look if it's telling you anything.



#15 Nemecek

Nemecek
  • 52 posts

Posted 30 November 2013 - 02:07 PM

Okay so I used http://www.draac.com/htmltester.html to paste the html to and get a visual of the page:

 

This is what I get with a fake user:

http://postimg.org/image/5urthfiwn/

 

This is what I get with a fake pass:

http://postimg.org/image/43yeik4nb/

 

And this is what I get when I enter my real user and pass: 

http://postimg.org/image/71xaspmmd/

 

It seems like i could maybe try just entering my username and then send a second post with my password. But I should be able to do it all in one post.



#16 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 30 November 2013 - 02:14 PM

You know you should be sending the request to login.phtml and not index.phtml, right?



#17 Nemecek

Nemecek
  • 52 posts

Posted 30 November 2013 - 02:37 PM

You know you should be sending the request to login.phtml and not index.phtml, right?

I use to have index.phtml in the referer but I got rid of it. The request gets sent to the url which you can see in my code is http://www.neopets.com/login.phtml

 

I must be sending it to the right place because when i do send false or incomplete information it tells me.


Edited by Nemecek, 30 November 2013 - 02:41 PM.


#18 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 30 November 2013 - 03:00 PM

Strange, if your headers are right, your data is right and your destination is right then I can't see how it wouldn't be working. O_o



#19 Nemecek

Nemecek
  • 52 posts

Posted 30 November 2013 - 03:36 PM

Strange, if your headers are right, your data is right and your destination is right then I can't see how it wouldn't be working. O_o

 

Thanks for the help. 



#20 Nemecek

Nemecek
  • 52 posts

Posted 12 December 2013 - 06:47 AM

Okay I'm finally done exams, YAY! 

 

I may have figured out what was wrong with my program. This is based purely on trial and error but it seems as though if i send my post request a second time it'll log me in. I think this happens because I believe that in order to log in you need to send the following cookies:

 

np_randseed=xxxxxxxxxxxxxxxxxxxx; np_uniq=pending; and a third one which I won't post.
 
With my first post request I send no cookies but neopets returns to me the above cookies.
Then with my second post the above cookies are sent with the request and I get returned the cookies I would expect from logging in.
 
I have a new problem though. As said, I assume I'm logging me in because I get returned the expected cookies. However I can't confirm this because when the program goes to print the html code it prints "?" 
 
I'm not sure whats going on because when I send the first post it prints the html code as it should but the second request only prints "?" as the html code. This occurs even when I enter incorrect credentials. Does anyone know what's going on? The program tells me that they both have Charset UTF-8 so I don't see why it would work for the first post but not the second. 


#21 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 12 December 2013 - 09:31 AM

Can you not just request another page after attempting to login and then checking if you're logged in on there?



#22 Nemecek

Nemecek
  • 52 posts

Posted 12 December 2013 - 09:52 AM

Can you not just request another page after attempting to login and then checking if you're logged in on there?

Thanks for the suggestion,

 

So I sent a GET request to go to the shopwizard and the html returned is fucked :p lol. I get returned a text looking something like this: 

 

»?{ô?}?è[3üÓ[ÚùÎ^Óë@-q?^Wm¥ÿôºÊ+?¨×U^áI½®ê?îÔk¹ÿËõ©^?z©cõZ?çæ%޸йeNÕiBê?½P9?³t@?f©<Â6Ðíd¿ý#kg?Mò?{ÒØ´êдl¨²óôlW/è+?ÓÅEÛUk?ÓgþØsãÉIS?)?õÁNx-?x2/+?¾xo?(??g¿ûÛ¥¥0ÆÿS1KâáÒæF`×<?ãwÿ?»Ká??<=G×BîËÊ?ÎgÐ?¿ûÏ?·¬Ú±ÿó?ý?¿ÿÿòïÿÛßýþ¯ÿjY¹?Xî¿ÿåÿþÿju¹÷°^üý¿ùw¿ÿ?ÿø¿þöß.+tX§ÿï_ÿÍÿù¯÷ÿú¿d?ôúnÃοÍÜ¡ÆÚ­è}ÞÍÞ56ùºh'á)¨i?VXF]óá\hM
Tûç\¨'?aà¹C
?c+åbµmmºÚí#[x»e?kçjÚê,ï0?E???Á1qÙ7P90QÉÎ
mu0?¸a|?2¡¬áNVí?ÀÚv&÷ÉrV`Kk5[ÒZ¿®ðA0#î?+)H?Î?¨:¿?PÌÕ|èûÀ?ÀRX8¡ã£ÕlÑ?~ |Ák[÷É ÏÀb·³?XA3buÄéé??ÿ_äL¾?ú¬?÷ÒÝIú8-??Åz²TÙÇ?«åé}f«?Úä)-bò?Ôéy ÏQÖÐO7ÿ(séGwú8ݪÃ? ? õ3*o?;}?q´¼?Ñ î?a0Û}æÏÐ?õÇêë?lù³zEÎlÒV¡?f'ÑQo
?¿?9?­£äê?:~K¯®?<oKÐBõÛõ×&Õûi'¡º?è+?2ý6ôfÃó¶¤?5oGå??·!ðSaÈGbìÆ°ä:?%ÁãÙ4?rÀUß µy?CÖå?òÒÏ?æbÑãµò 6Ê^â?T?,HnïaQCËØ9ئǫôöG?GLþ?Ã?§¸¾Tû¦KòT<I¢ª?ªÚÞ©åZ®ÙR¿µZÚÃ3Wê¹?k??6¾j?jté&Ì??U#?Î?
?-TÉÁH1?º??¹¾pì<9¾ò¸6¾Î*y´ØiÊ=þ'¯d]XüÔk®ïJ Ç>±a?ô]TÙÔXª? í¢?ë?§*
ÉjÝlñ³ë2?ZtZ¿Rot±7{?³wuýëÔÛÅTª[ßM?³±ØerÀ©ó?í³È«®0èÆ·$£9Ó¤¿£ ¨3òÎÞ,?IÚ??ÎÍUZ¶ ?¥Ñ5Â?º ö??îó;Ãð¾5ö?ð®??ÖXÌý¸?1òGfEy%ñ8LÈ©G"?®VªGUDtþ/s(Ò½?P:nz|Þ¥?K(´ioñAx³?F=±X²%{N>Kfìuäk?'ÝxÕ)·%YßÞ¤«ß??â¥l4G?5?'ImÇ<N¡?ö?Êg¨?$Ò QËd»}$1¿«´Ì?Ï×æ2þ¹TFúnûá¡??ú_í©ü?ÅÈnº©ÀÒ¥Ë:m?t?ÚMEâfQ?Ô©ÀV???SämÈKÝ®îÖ?I¯ü<rWÖ¥ïR*òî O&
k±ºFK¶??r?
¦?PÖ"£&¹j¯?ëÆ?4¡ÔXÅlQS??Rs?B??Ìa*A¹?
9]xØISJyAnªsÁ´ãiǬ#×?§ÆAa\ü??[!-ª'ÜtD¶h?Ü2ý?ËÆþrIsxtøNÝ:¢£?í¤3kéùA>éé?-NÎéØ??h#$µVÔÌä?çn]OP9úÒX"¦Ù?u?
°Û.vÜ^«Ð»Fß.8?ÜLÜTRÒ um¾?úmå?lA¢v??íwÊ£?ébO­ºá?Ü¡kxpU÷Ü+ù??E`)¾Ð6+å?2/?Zô¯?#95j$~
"õ]s¶AQ}?Ë¥£(%?ßíì&¾âß;4ZüL³î?¾Ó?ù?J?Ø?J)?Z³®??k·eO\P?oTdûíý}*¡DA??ô??î(L.¡,z?Ë7äFÑ?3«??Ü@[2ȤI},ñQ?x`"§(£þÙ¿0?7??Xè._6¸r?úÌsG\»CQAyõ?ÍÝÖ?êÅ?¸1õO?â¬ÿÒ>¬gZ[¯¦??ðAϾ LrH?ßBWdäIÞË?]?¡KÈ¡?kªØ)С4&ër¶.ïÝy?çôB?~¨+?»Yx6é-B*?`©4%}?Õûl¢L?*a¨¹kå$dO?{?wypÑ4`ö:Ù??Ðr\,>F?ð?L.ñã
t?"ä~Z@%ææzIdrÝH?HèêÃÀÅÊ
6(¯££¼<Ⱦð??¢­Sí?ûR5?nÒ[ÝجÀÅ4?öÆ1Ê? (?7A®1\¤O÷Ë?ðÛØ1û:ÜÆX`v$?f ?.VêÃÛ¹NÊ???C¼??&hóI87?}X>ÁktU&áWò2
 
and it still says it's UTF-8 


#23 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 12 December 2013 - 09:59 AM

 

Thanks for the suggestion,

 

So I sent a GET request to go to the shopwizard and the html returned is fucked :p lol. I get returned a text looking something like this: 

 

»?{ô?}?è[3üÓ[ÚùÎ^Óë@-q?^Wm¥ÿôºÊ+?¨×U^áI½®ê?îÔk¹ÿËõ©^?z©cõZ?çæ%޸йeNÕiBê?½P9?³t@?f©<Â6Ðíd¿ý#kg?Mò?{ÒØ´êдl¨²óôlW/è+?ÓÅEÛUk?ÓgþØsãÉIS?)?õÁNx-?x2/+?¾xo?(??g¿ûÛ¥¥0ÆÿS1KâáÒæF`×<?ãwÿ?»Ká??<=G×BîËÊ?ÎgÐ?¿ûÏ?·¬Ú±ÿó?ý?¿ÿÿòïÿÛßýþ¯ÿjY¹?Xî¿ÿåÿþÿju¹÷°^üý¿ùw¿ÿ?ÿø¿þöß.+tX§ÿï_ÿÍÿù¯÷ÿú¿d?ôúnÃοÍÜ¡ÆÚ­è}ÞÍÞ56ùºh'á)¨i?VXF]óá\hM
Tûç\¨'?aà¹C
?c+åbµmmºÚí#[x»e?kçjÚê,ï0?E???Á1qÙ7P90QÉÎ
mu0?¸a|?2¡¬áNVí?ÀÚv&÷ÉrV`Kk5[ÒZ¿®ðA0#î?+)H?Î?¨:¿?PÌÕ|èûÀ?ÀRX8¡ã£ÕlÑ?~ |Ák[÷É ÏÀb·³?XA3buÄéé??ÿ_äL¾?ú¬?÷ÒÝIú8-??Åz²TÙÇ?«åé}f«?Úä)-bò?Ôéy ÏQÖÐO7ÿ(séGwú8ݪÃ? ? õ3*o?;}?q´¼?Ñ î?a0Û}æÏÐ?õÇêë?lù³zEÎlÒV¡?f'ÑQo
?¿?9?­£äê?:~K¯®?<oKÐBõÛõ×&Õûi'¡º?è+?2ý6ôfÃó¶¤?5oGå??·!ðSaÈGbìÆ°ä:?%ÁãÙ4?rÀUß µy?CÖå?òÒÏ?æbÑãµò 6Ê^â?T?,HnïaQCËØ9ئǫôöG?GLþ?Ã?§¸¾Tû¦KòT<I¢ª?ªÚÞ©åZ®ÙR¿µZÚÃ3Wê¹?k??6¾j?jté&Ì??U#?Î?
?-TÉÁH1?º??¹¾pì<9¾ò¸6¾Î*y´ØiÊ=þ'¯d]XüÔk®ïJ Ç>±a?ô]TÙÔXª? í¢?ë?§*
ÉjÝlñ³ë2?ZtZ¿Rot±7{?³wuýëÔÛÅTª[ßM?³±ØerÀ©ó?í³È«®0èÆ·$£9Ó¤¿£ ¨3òÎÞ,?IÚ??ÎÍUZ¶ ?¥Ñ5Â?º ö??îó;Ãð¾5ö?ð®??ÖXÌý¸?1òGfEy%ñ8LÈ©G"?®VªGUDtþ/s(Ò½?P:nz|Þ¥?K(´ioñAx³?F=±X²%{N>Kfìuäk?'ÝxÕ)·%YßÞ¤«ß??â¥l4G?5?'ImÇ<N¡?ö?Êg¨?$Ò QËd»}$1¿«´Ì?Ï×æ2þ¹TFúnûá¡??ú_í©ü?ÅÈnº©ÀÒ¥Ë:m?t?ÚMEâfQ?Ô©ÀV???SämÈKÝ®îÖ?I¯ü<rWÖ¥ïR*òî O&
k±ºFK¶??r?
¦?PÖ"£&¹j¯?ëÆ?4¡ÔXÅlQS??Rs?B??Ìa*A¹?
9]xØISJyAnªsÁ´ãiǬ#×?§ÆAa\ü??[!-ª'ÜtD¶h?Ü2ý?ËÆþrIsxtøNÝ:¢£?í¤3kéùA>éé?-NÎéØ??h#$µVÔÌä?çn]OP9úÒX"¦Ù?u?
°Û.vÜ^«Ð»Fß.8?ÜLÜTRÒ um¾?úmå?lA¢v??íwÊ£?ébO­ºá?Ü¡kxpU÷Ü+ù??E`)¾Ð6+å?2/?Zô¯?#95j$~
"õ]s¶AQ}?Ë¥£(%?ßíì&¾âß;4ZüL³î?¾Ó?ù?J?Ø?J)?Z³®??k·eO\P?oTdûíý}*¡DA??ô??î(L.¡,z?Ë7äFÑ?3«??Ü@[2ȤI},ñQ?x`"§(£þÙ¿0?7??Xè._6¸r?úÌsG\»CQAyõ?ÍÝÖ?êÅ?¸1õO?â¬ÿÒ>¬gZ[¯¦??ðAϾ LrH?ßBWdäIÞË?]?¡KÈ¡?kªØ)С4&ër¶.ïÝy?çôB?~¨+?»Yx6é-B*?`©4%}?Õûl¢L?*a¨¹kå$dO?{?wypÑ4`ö:Ù??Ðr\,>F?ð?L.ñã
t?"ä~Z@%ææzIdrÝH?HèêÃÀÅÊ
6(¯££¼<Ⱦð??¢­Sí?ûR5?nÒ[ÝجÀÅ4?öÆ1Ê? (?7A®1\¤O÷Ë?ðÛØ1û:ÜÆX`v$?f ?.VêÃÛ¹NÊ???C¼??&hóI87?}X>ÁktU&áWò2
 
and it still says it's UTF-8 

 

 

What headers did you send and receive? You should get a Content-Encoding header that will tell you what you need to do with this... Are you sending an Accept-Encoding header?



#24 Nemecek

Nemecek
  • 52 posts

Posted 12 December 2013 - 10:55 AM

What headers did you send and receive? You should get a Content-Encoding header that will tell you what you need to do with this... Are you sending an Accept-Encoding header?

Ah you nailed it!

 

I was using httpurlconnection.getContentType(); which returned to me UTF-8

but really I should have been using httpurlconnection.getEncodingContent(); which returns gzip and now it works

 

Thanks a lot I'm really excited that I've finally made progress.

 

Step 1: Login (check)

Step 2: Dominate Neopia ()

Step 3: Get Iced ()

Step 4: Start all over again ()



#25 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 12 December 2013 - 11:05 AM

This should fix your initial issue as well - if you decompress the gzip body you should then be able to perform a check on whether you're logged in or not.

 

Also, it's important that you have the right tooling when you're writing things like this.

 

Download Fiddler, it will listen to all of your web requests and responses and display them in an easy-to-read way, with the request and the response. Any requests your program makes will be listed when they are made.

 

You can also do some very cool things with it such as decompress third-party serialization techniques (AMF, for example), decrypt SSL, repeat certain requests, etc. You can save requests to look at later (which is very handy when you're writing a neopets program).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users