Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Improved _INetGetSource


  • Please log in to reply
12 replies to this topic

#1 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 25 August 2005 - 09:55 PM

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]


Plain Text         
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, 27 September 2005 - 04:49 PM.

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







#2 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,970 posts

Posted 25 August 2005 - 11:05 PM

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

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


#3 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 25 August 2005 - 11:07 PM

COM + non existing URL = total crash.
My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

#4 seandisanti

seandisanti

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,927 posts

Posted 26 August 2005 - 01:08 PM

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, 26 August 2005 - 01:09 PM.

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

#5 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 03 September 2005 - 11:07 PM

litle bugfix.

also i was wondering why au3check claims that my array init is wrong ?
My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

#6 theguy0000

theguy0000

    Benevolent Dictator

  • Active Members
  • PipPipPipPipPipPip
  • 3,750 posts

Posted 05 September 2005 - 01:50 AM

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

#7 Gigglestick

Gigglestick

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 501 posts

Posted 06 September 2005 - 06:32 PM

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

#8 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 14 September 2005 - 09:02 PM

small bugfix.

ps;
im sorry, but i do now know alot about com ;)
all i know is that you can use AutoIt.Error
My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

#9 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 27 September 2005 - 05:00 PM

see edit 5.

i would also like this to replace the current UDF in the beta.
My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

#10 Jos

Jos

    oh joy ...

  • Developers
  • 22,534 posts

Posted 27 September 2005 - 08:24 PM

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.
  :)


#11 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 27 September 2005 - 09:13 PM

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

#12 Ic3c0ld

Ic3c0ld

    Seeker

  • Active Members
  • 33 posts

Posted 13 October 2005 - 12:57 AM

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


#13 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 13 October 2005 - 01:03 PM

try typing "bla" in that input box.
My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users