Sign in to follow this  
Followers 0

Improved _INetGetSource

13 posts in this topic

#1 ·  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

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites



#2 ·  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


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#4 ·  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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#6 ·  Posted

useful script!

- Matt :whistle:


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

#7 ·  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?


My UDFs: ExitCodes

Share this post


Link to post
Share on other sites

#10 ·  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.


Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#12 ·  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

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