Jump to content

InetGetSource with Post string


 Share

Recommended Posts

Hello everyone Posted Image

You all know the function on Inet.au3 "_INetGetSource". The bad is: It's need a dll and you can not send a Post string (execpt u send manually a header)

So ive created a function (_InetGetSourcePost, very creative, like i am :) ) with witch u can Download the Sourcecode with Post sending.

Youll receive the BackHeader and the Sourcecode in an Array.

Ok, sorry for my bad english, but i hope u like my "autoish" :(

Function:

#include-once


;===============================================================================
;
; Function Name:    _INetGetSourcePost()
; Description:      Gets the source from an URL without writing a temp file and you can send a Post.
; Parameter(s):     $sURL = The URL of the site.
;              $sPost = The Post to send
; Requirement(s):   -
; Return Value(s):  On Success - Return a array with $aReturn[0] = Backheader and $aReturn[1] = Sourcecode
;                   On Failure - 0  and sets @ERROR
;               @error = 1: Post or URL is nothing
;               @error = 2: Error by RegularExpression
;               @error = 3: $sHost or $sHttp1 is nothing
;               @error = 4: Can not get IP of Host
;               @error = 5: Can not connect to host
;               @error = 6: Nothing can be send
;               @error = 7: Connection abborted while receiving
; Author(s):        GtaSpider
;
;===============================================================================



Func _INetGetSourcePost($sURL, $sPost)
    Local $iSocket, $sHeader, $sRecv, $iIP, $sHost, $aRegExp, $sHttp1,$iErr,$iSend,$aReturn[2]
    
    If $sURL = '' Or $sPost = '' Then Return SetError(1, 0, 0) 
    
    If StringLeft($sURL, 7) <> 'http://' And StringLeft($sURL, 8) <> 'https://' Then $sURL = "http://" & $sURL
    If StringRight($sURL, 1) <> "/" Then $sURL &= "/"
    
    $aRegExp = StringRegExp($sURL, "http?://(.*?)/", 3)
    If @error Then Return SetError(2, 0, 0)
    
    $sHost = $aRegExp[0]
    If $sHost = '' Then Return SetError(3, 0, 0)
    
    $sHttp1 = StringTrimLeft($sURL,StringInStr($sURL,"/",-1,3)-1)
    If $sHttp1 = '' Then Return SetError(3, 0, 0)
    
    
    $sHeader = "POST " & $sHttp1 & " HTTP/1.1" & @CRLF & _
            "Host: " & $sHost & @CRLF & _
            "User-Agent: AutoIt v3" & @CRLF & _
            "Content-Length: " & StringLen($sPost) & @CRLF & @CRLF & $sPost
            
            
    TCPStartup() ;If not already done
    $iIP = TCPNameToIP($sHost)
    If $iIP = '' Or StringInStr($iIP, ".") = 0 Then Return SetError(4, 0, 0)
    $iSocket = TCPConnect($iIP, 80)
    If @error Or $iSocket < 0 Then Return SetError(5, 0, 0)
    
    $iSend = TCPSend($iSocket, $sHeader)
    If @error Or $iSend < 1 Then Return SetError(6, 0, 0)
    
    
    While 1
        $sRecv = TCPRecv($iSocket, 1024)
        $iErr = @error
        If $sRecv <> '' Then
            While 1
                $sRecv &= TCPRecv($iSocket, 1024)
                If @error Then ExitLoop 2
            WEnd
        EndIf
        If $iErr Then Return SetError(7,0,0)
    WEnd
    
    $aReturn[0] = StringLeft($sRecv,StringInStr($sRecv,@CRLF&@CRLF)-1)
    $aReturn[1] = StringTrimLeft($sRecv,StringLen($aReturn[0])+4)
    Return $aReturn
EndFunc   ;==>_INetGetSourcePostoÝ÷ ØLZ^jëh×6#include <INETv2.au3>
;by GtaSpider


SplashTextOn("","Downloading...",200,20,-1,-1,1)
$aSource = _INetGetSourcePost("http://rs255.rapidshare.com/files/110695594/cardr.rar","dl.start=Free")
If @error Then Exit MsgBox(16,"","Error: "&@error)
FileWrite("TestFile.html",$aSource[1])
RunWait('"' & @ComSpec & '" /c "'&@ScriptDir&'\TestFile.html"', '', @SW_HIDE)
SplashOff()

In attachment there are the Include and the Expample

Your Spider

Edit: HotFix

INETv2.zip

Edited by GtaSpider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

Hi

Nice idea, James :) There are a lot of applications to use for.

It can do many things, what the IE.au3 can do, but a lot of faster because the IE doesnt have to load.

@ludocus: isn't it? Thanks :(

your Spider

sry4my bad engl

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

Hi

No, dl.start is the name.

Look at the Source:

<tr><td><b>Bitte den Download-Typ w&auml;hlen:</td><td align="center"><input type="submit" name="dl.start" value="PREMIUM"></td><td align="center"><input type="submit" name="dl.start" value="Free"></td></tr>

Here you see, if you push the "Free" button on http://rs255.rapidshare.com/files/110695594/cardr.rar , he sending POST with name dl.start and Value free (name=Value in this example dl.start=Free)

Your Spider

Edited by GtaSpider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...