Sign in to follow this  
Followers 0

Improved _INetGetSource

13 posts in this topic

Posted (edited)

i would like this tested before i submit it to some dev.

[edit]

made the buffer from 3 to 256

[/edit]

[edit2]

removed :whistle:

[/edit2]

[edit3]

stripping leftover @CR & @LF at the end

[/edit3]

[edit4]

instead of looping i just trim the last 2 chars to get rid of the leftover enter

reduced filesize a bit

removed edit 2 since it does support ftp://

[/edit4]

[edit5]

added support for Headers & changed user-agent to "AutoIt v3"

[/edit5]

Func _INetGetSource($s_URL, $s_Header = '')
    Local $h_DLL = DllOpen("wininet.dll"), $ai_IO, $ai_IOU, $ai_ICH, $ai_IRF[5] = [0, 0, '', 0, 1], $s_Buf = ''
    $ai_IO = DllCall($h_DLL, 'int', 'InternetOpen', 'str', "AutoIt v3", 'int', 0, 'str', '', 'str', '', 'int', 0)
    If @error Or $ai_IO[0] = 0 Then
        DllClose($h_DLL)
        SetError(1)
        Return 0
    EndIf
    $ai_IOU = DllCall($h_DLL, 'int', 'InternetOpenUrl', 'int', $ai_IO[0], 'str', $s_URL, 'str', $s_Header, 'int', StringLen($s_Header), 'int', 0x80000000, 'int', 0)
    If @error Or $ai_IOU[0] = 0 Then
        DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IO[0])
        DllClose($h_DLL)
        SetError(1)
        Return 0
    EndIf
    Local $v_Struct = DllStructCreate ('udword')
    While $ai_IRF[4] <> 0
        $s_Buf &= StringMid($ai_IRF[2], 1, $ai_IRF[4])
        $ai_IRF = DllCall($h_DLL, 'int', 'InternetReadFile', 'int', $ai_IOU[0], 'str', "", 'int', 256, 'ptr', DllStructGetPtr ($v_Struct, 1))
        $ai_IRF[4] = DllStructGetData ($v_Struct, 1)
    WEnd
    DllStructDelete ($v_Struct)
    DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IOU[0])
    DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IO[0])
    DllClose($h_DLL)
    Return StringTrimRight($s_Buf, 1)
EndFunc;==>_INetGetSource

ConsoleWrite(_INetGetSource('http://www.autoitscript.com') & @LF)

to make cameronsdad happy:

(related to InternetReadFile)

LPVOID had nothing to do with it, just using 'str' was good.

the problem was with "LPDWORD lpdwNumberOfBytesRead" i first just used a 0 and now i use Dllstruct (im sure there is a cleaner way :dance:)

Edited by w0uter

Share this post


Link to post
Share on other sites



Posted

w0uter,

I just curious why you say this is better/more control than COM?

Using COM you can get the same result in 4 lines of code:

Func _INetGetSource($s_URL)
    $WinHttpReq = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $WinHttpReq.Open("GET", $s_URL, false)
    $WinHttpReq.Send()
    Return $WinHttpReq.ResponseText
EndFunc

Dale

Share this post


Link to post
Share on other sites

Posted

COM + non existing URL = total crash.

Share this post


Link to post
Share on other sites

Posted (edited)

to make cameronsdad happy:

(related to InternetReadFile)

LPVOID had nothing to do with it, just using 'str' was good.

the problem was with "LPDWORD lpdwNumberOfBytesRead" i first just used a 0 and now i use Dllstruct (im sure there is a cleaner way :whistle:)

<{POST_SNAPBACK}>

wow, i almost never look in this forum (mostly just support because thinking on scripts helps pass time at work) and i can't tell you how surprised i was to see my name. Thanks for remembering my request, and yes, it did in fact make me happy.

***edit*** realized i'd quoted all of your code etc and didn't think that was necessary for the small amount i was actually replying to, so i removed it...

Edited by cameronsdad

Share this post


Link to post
Share on other sites

Posted

litle bugfix.

also i was wondering why au3check claims that my array init is wrong ?

Share this post


Link to post
Share on other sites

Posted

useful script!

- Matt :whistle:

Share this post


Link to post
Share on other sites

Posted

Func _INetGetSource($s_URL)
    $WinHttpReq = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $WinHttpReq.Open("GET", $s_URL, false)
    $WinHttpReq.Send()
    Return $WinHttpReq.ResponseText
EndFunc

<{POST_SNAPBACK}>

COM + non existing URL = total crash.

<{POST_SNAPBACK}>

wOuter, I like your code.

For learning purposes, I'd like to know if there is a way to use the WinHttpRequest.onerror event to trap a failure and use Dale's shorter code?

Share this post


Link to post
Share on other sites

Posted

small bugfix.

ps;

im sorry, but i do now know alot about com ;)

all i know is that you can use AutoIt.Error

Share this post


Link to post
Share on other sites

Posted

see edit 5.

i would also like this to replace the current UDF in the beta.

Share this post


Link to post
Share on other sites

Posted

see edit 5.

i would also like this to replace the current UDF in the beta.

Could you do me a favor and PM or mail me any updates to UDF's (func or docs) because there is always a good chance I am missing posts like this .. tnx ;)

Got this one done ...... so no need to sent that.

Share this post


Link to post
Share on other sites

Posted

okey will remember that.

Share this post


Link to post
Share on other sites

Posted

wOuter, I like your code.

For learning purposes, I'd like to know if there is a way to use the WinHttpRequest.onerror event to trap a failure and use Dale's shorter code?

WoUter I also like your code I use this in one.

$s_URL = InputBox("WebPage", "Type WebPage To Get Source From")

_INetGetSource($s_URL)

Func _INetGetSource($s_URL)
    $WinHttpReq = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $WinHttpReq.Open("GET", $s_URL, false)
    $WinHttpReq.Send()
    ClipPut($WinHttpReq.ResponseText)
    Run("Notepad.exe")
    WinWaitActive("Untitled - Notepad")
    Send("{CTRLDOWN}v{CTRLUP}")
EndFunc

Share this post


Link to post
Share on other sites

Posted

try typing "bla" in that input box.

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.