Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32

Thread: [Various] HTTP Wrappers

  1. #1

    Joined
    Dec 2011
    Posts
    488
    Thanks
    303
    Thanked
    559/263
    DL/UL
    13/4
    Mentioned
    34 times
    Time Online
    1h 58m
    Avg. Time Online
    N/A

    [Various] HTTP Wrappers

    Last edited by j03; 09-22-2015 at 06:33 AM.

  2. The Following 2 Users Say Thank You to Miguel For This Useful Post:

    Cody. (09-10-2012),taeryn (07-13-2012)

  3. #2
    Reemer's Avatar
    Joined
    Dec 2011
    Posts
    639
    Userbars
    8
    Thanks
    364
    Thanked
    446/256
    DL/UL
    39/0
    Mentioned
    203 times
    Time Online
    4d 13h 47m
    Avg. Time Online
    1m
    Java HTTP Wrapper
    Written by Zer0,

    Code:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.zip.*;
    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    
    public class Connection implements Serializable {
       static final long serialVersionUID = 1L;
       
       String domain, referer;
       Map<String,String> cookies;
       
       static String rpUseragent = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.14) Gecko/20080509 Firefox/2.0.0.14";
       static String rpAcceptText = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
       static String rpAcceptPng = "image/png,image/*;q=0.8,*/*;q=0.5";
       static String rpAcceptLanguage = "en-us,en;q=0.5";
       static String rpAcceptEncoding = "gzip, deflate";
       static String rpAcceptCharset = "ISO-8859-1,utf-8;q=0.7,*;q=0.7";
       static String rpKeepAlive = "300";
       static String rpConnection = "keep-alive";
       static String rpContentType = "application/x-www-form-urlencoded";
       
       public Connection( String domain, Map<String,String> cookies, String referer ) {
          this.domain = domain;
          this.cookies = cookies;
          this.referer = referer;
       }
       
       public Connection( String domain, Map<String,String> cookies ) {
          this( domain, cookies, null );
       }
       
       public Connection( String domain, String referer ) {
          this( domain, new HashMap<String,String>(), referer );
       }
       
       public Connection( String domain ) {
          this( domain, new HashMap<String,String>(), 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;
          }
       }
       
       public String post( String url, String[][] data ) {
          if( url.charAt( 0 ) == '/' )
             url = domain + url;
          
          try {
             HttpURLConnection conn = (HttpURLConnection)( new URL( url.replaceAll( " ", "%20" ) ).openConnection() );
             setRequestProperties( conn );
             conn.setRequestMethod( "POST" );
             conn.setDoOutput( true );
             
             StringBuilder sb = new StringBuilder();
             
             for( int i = 0; i < data[0].length; i++ )
                sb.append( URLEncoder.encode( data[0][i], "UTF-8" ) ).append( '=' ).append( URLEncoder.encode( data[1][i], "UTF-8" ) ).append( '&' );
             
             conn.setRequestProperty( "Content-Type", rpContentType );
             conn.setRequestProperty( "Content-Length", Integer.toString( sb.length()-1 ) );
             
             PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) ) );
             out.write( sb.substring( 0, sb.length()-1 ) );
             out.close();
             
             referer = url;
             return read( conn );
          } catch( IOException e1 ) {
             e1.printStackTrace();
             return null;
          }
       }
       
       public BufferedImage getImage( String url ) {
          try {
             HttpURLConnection conn = (HttpURLConnection)( new URL( ( url.charAt( 0 ) == '/' ? domain+url : url ).replaceAll( " ", "%20" ) ).openConnection() );
             setRequestProperties( conn );
             conn.setRequestMethod( "GET" );
             conn.setRequestProperty( "Accept", rpAcceptPng );
             return ImageIO.read( conn.getInputStream() );
          } catch( IOException e1 ) {
             e1.printStackTrace();
             return null;
          }
       }
       
       public boolean hasCookie( String key ) {
          return cookies.containsKey( key );
       }
       
       public String getCookieString() {
          StringBuilder sb = new StringBuilder();
          
          for( String s : cookies.keySet() )
             sb.append( s ).append( '=' ).append( cookies.get( s ) ).append( ';' );
          
          return sb.toString();
       }
       
       private void setRequestProperties( HttpURLConnection conn ) {
          conn.setInstanceFollowRedirects( false );
          conn.setRequestProperty( "User-Agent", rpUseragent );
          conn.setRequestProperty( "Accept", rpAcceptText );
          conn.setRequestProperty( "Accept-Language", rpAcceptLanguage );
          conn.setRequestProperty( "Accept-Encoding", rpAcceptEncoding );
          conn.setRequestProperty( "Accept-Charset", rpAcceptCharset );
          conn.setRequestProperty( "Keep-Alive", rpKeepAlive );
          conn.setRequestProperty( "Connection", rpConnection );
          
          if( referer != null && referer.length() != 0 )
             conn.setRequestProperty( "Referer", referer );
          
          if( cookies != null && cookies.size() != 0 )
             conn.setRequestProperty( "Cookie", getCookieString() );
       }
       
       private String read( HttpURLConnection conn ) throws IOException {
          BufferedReader in = null;
          
          if( conn.getContentEncoding() == null )
             in = new BufferedReader( new InputStreamReader( conn.getInputStream() ) );
          else
             if( conn.getContentEncoding().equalsIgnoreCase( "gzip" ) )
                in = new BufferedReader( new InputStreamReader( new GZIPInputStream( conn.getInputStream() ) ) );
             else if( conn.getContentEncoding().equalsIgnoreCase( "deflate" ) )
                in = new BufferedReader( new InputStreamReader( new InflaterInputStream( conn.getInputStream(), new Inflater( true ) ) ) );
          
          StringBuilder sb = new StringBuilder();
          String s;
          
          while( ( s = in.readLine() ) != null )
             sb.append( s ).append( '\n' );
          
          putCookies( conn.getHeaderFields().get( "Set-Cookie" ) );
          return sb.toString();
       }
       
       private void putCookies( List<String> cookieList ) {
          if( cookieList == null )
             return;
          
          int index;
          
          for( String cookie : cookieList )
             cookies.put( cookie.substring( 0, index = cookie.indexOf( '=' ) ), cookie.substring( index+1, cookie.indexOf( ';', index ) ) );
       }
    }

  4. The Following User Says Thank You to Reemer For This Useful Post:

    Miguel (03-11-2012)

  5. #3
    Saiyan Race
    j03's Avatar
    Joined
    Dec 2011
    Posts
    13,722
    Userbars
    166
    Thanks
    5,906
    Thanked
    33,078/6,609
    DL/UL
    23/36
    Mentioned
    3,867 times
    Time Online
    563d 5h 25m
    Avg. Time Online
    3h 13m
    ./m Y U NO POST PYTHON WRAPPER?
    (you need an account to see links)
    (you need an account to see links)(you need an account to see links)

    ------------------------
    [02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
    ------------------------


  6. #4

    Joined
    Dec 2011
    Posts
    488
    Thanks
    303
    Thanked
    559/263
    DL/UL
    13/4
    Mentioned
    34 times
    Time Online
    1h 58m
    Avg. Time Online
    N/A
    Because I need to salvage it off one of three TB hard drives and that would be a major pain in the ass

  7. #5
    Saiyan Race
    j03's Avatar
    Joined
    Dec 2011
    Posts
    13,722
    Userbars
    166
    Thanks
    5,906
    Thanked
    33,078/6,609
    DL/UL
    23/36
    Mentioned
    3,867 times
    Time Online
    563d 5h 25m
    Avg. Time Online
    3h 13m
    Trust me, it'll be worth it in the end.
    (you need an account to see links)
    (you need an account to see links)(you need an account to see links)

    ------------------------
    [02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
    ------------------------


  8. #6
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    NiteWrapper for VB6.

    One of my favorite wrappers (has a built-in fast OCR)

  9. The Following User Says Thank You to Zachafer For This Useful Post:

    Miguel (03-11-2012)

  10. #7
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    cxWrapper by cx323 (VB6, C#, VBNET)

    Code:
    Private Declare Function Req Lib "cxWrapper.dll" (ByVal Method As String, ByVal URL As String, ByVal Referrer As String) As String
    Private Declare Function DownloadImage Lib "cxWrapper.dll" (ByVal Method As String, ByVal URL As String, ByVal Referrer As String, ByVal Path As String) As Boolean
    Private Declare Sub ClearCookies Lib "cxWrapper.dll" ()
    Private Declare Sub ClearStoredCookies Lib "cxWrapper.dll" ()
    Private Declare Function StoreCookies Lib "cxWrapper.dll" (ByVal key As String, ByVal erase_current As Boolean) As Boolean
    Private Declare Function LoadCookies Lib "cxWrapper.dll" (ByVal key As String) As Boolean
    Private Declare Function SetUA Lib "cxWrapper.dll" (ByVal UserAgent As String) As Boolean
    Private Declare Function IpicDownload Lib "cxWrapper.dll" (ByVal Method As String, ByVal URL As String, ByVal Referrer As String) As IPicture
    Last edited by Zachafer; 03-11-2012 at 10:44 PM.

  11. The Following 2 Users Say Thank You to Zachafer For This Useful Post:

    j03 (04-03-2012),Miguel (03-11-2012)

  12. #8
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    VB6 HaloWrapper by Raui
    Attached Files Attached Files

  13. The Following User Says Thank You to Zachafer For This Useful Post:

    Miguel (04-03-2012)

  14. #9

    Joined
    Dec 2011
    Posts
    488
    Thanks
    303
    Thanked
    559/263
    DL/UL
    13/4
    Mentioned
    34 times
    Time Online
    1h 58m
    Avg. Time Online
    N/A
    Wondering if I can get average load times of google.com for each of these wrappers?

  15. #10
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    Quote Originally Posted by ./m View Post
    Wondering if I can get average load times of google.com for each of these wrappers?
    Tonight? Or tomorrow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •