Jump to content

_INetGetSource with Cookie or any other header


mary
 Share

Recommended Posts

Please, if you have an exemple with cookie session autentification using _INetGetSource, let as know. I try this UDF but no succeed

here is my exemple:

#include <INet.au3>

$url="http://www.awebservice.com?"
$Data_to_Post="abc=10&id=12"


$My_valid_cookies_session="Cookie:UserId=aeerehgftreuusffe12ehggf" 

; this cookie is obtened by Live Http Headers (Firefox) ;and it work great with Curl or Wget

$html_source_reponse = _INetGetSource($url & $Data_to_Post, $My_valid_cookies_session)

consolewrite($html_source_reponse )

please what is wrong in my code ? (user agent or any other header item is not necessary ! only Cookie)

thinks a lot

Edited by mary
Link to comment
Share on other sites

Please, if you have an exemple with cookie session autentification using _INetGetSource, let as know. I try this UDF but no succeed

here is my exemple:

$html_source_reponse = _INetGetSource($url & $Data_to_Post, $My_valid_cookies_session)

please what is wrong in my code ? (user agent or any other header item is not necessary ! only Cookie)

thinks a lot

did you read the help file for _INetGetSource?

There is no way to POST data and there is NO second parameter (which you believe to be the Cookie), at least

in my version of the help file....

You need to use the IE Automation commands (_IExyz). See help file samples.....

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

did you read the help file for _INetGetSource?

There is no way to POST data and there is NO second parameter (which you believe to be the Cookie), at least

in my version of the help file....

You need to use the IE Automation commands (_IExyz). See help file samples.....

no, no...look at INET.AU udf, the prototype of _inetgetsource is :

Func _InetGetSource($url, $headers='')

balabla


EndFun

The autor of this func is Wouter (?), so may be he forgot to add some thing in help file

Link to comment
Share on other sites

Here Wouter code, $s_Header argument is missed in help file !

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
Edited by mary
Link to comment
Share on other sites

Try this.

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://www.awebservice.com?", true)
$oHTTP.SetRequestHeader("Cookie:", "UserId=aeerehgftreuusffe12ehggf")
$oHTTP.SetRequestHeader("Content-Length", StringLen("abc=10&id=12"))
$oHTTP.Send("abc=10&id=12")
ConsoleWrite($oHTTP.ResponseText & @CRLF)
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Try this.

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://www.awebservice.com?", true)
$oHTTP.SetRequestHeader("Cookie:", "UserId=aeerehgftreuusffe12ehggf")
$oHTTP.SetRequestHeader("Content-Length", StringLen("abc=10&id=12"))
$oHTTP.Send("abc=10&id=12")
ConsoleWrite($oHTTP.ResponseText & @CRLF)
thinks, I know that way. But my goal is to use dllcall without com issues. so my question is how to do same think with Wouter code (_inetGetsource) ?
Link to comment
Share on other sites

You may know this, but it is easy to trap COM errors. Here is how I handle it in IE.au3:

$oIEErrorHandler = ObjEvent("AutoIt.Error", "__IEInternalErrorHandler")

Func __IEInternalErrorHandler()
    $IEComErrorScriptline = $oIEErrorHandler.scriptline
    $IEComErrorNumber = $oIEErrorHandler.number
    $IEComErrorNumberHex = Hex($oIEErrorHandler.number, 8)
    $IEComErrorDescription = StringStripWS($oIEErrorHandler.description, 2)
    $IEComErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2)
    $IEComErrorSource = $oIEErrorHandler.Source
    $IEComErrorHelpFile = $oIEErrorHandler.HelpFile
    $IEComErrorHelpContext = $oIEErrorHandler.HelpContext
    $IEComErrorLastDllError = $oIEErrorHandler.LastDllError
    $IEComErrorOutput = ""
    $IEComErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR
    $IEComErrorOutput &= "----> $IEComErrorScriptline = " & $IEComErrorScriptline & @CR
    $IEComErrorOutput &= "----> $IEComErrorNumberHex = " & $IEComErrorNumberHex & @CR
    $IEComErrorOutput &= "----> $IEComErrorNumber = " & $IEComErrorNumber & @CR
    $IEComErrorOutput &= "----> $IEComErrorWinDescription = " & $IEComErrorWinDescription & @CR
    $IEComErrorOutput &= "----> $IEComErrorDescription = " & $IEComErrorDescription & @CR
    $IEComErrorOutput &= "----> $IEComErrorSource = " & $IEComErrorSource & @CR
    $IEComErrorOutput &= "----> $IEComErrorHelpFile = " & $IEComErrorHelpFile & @CR
    $IEComErrorOutput &= "----> $IEComErrorHelpContext = " & $IEComErrorHelpContext & @CR
    $IEComErrorOutput &= "----> $IEComErrorLastDllError = " & $IEComErrorLastDllError & @CR
    If $_IEErrorNotify Or $__IEAU3Debug Then ConsoleWrite($IEComErrorOutput & @CR)
    SetError($_IEStatus_ComError)
    Return
EndFunc   ;==>__IEInternalErrorHandler

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

Link to comment
Share on other sites

Right Dale ! your code is clean and handle well com error.

As I told, my question only technical (about using DllCall Like W0uter _InetGetSource ).

I asked about DllCall because it is more rapid to send a Get HTTP Request (millisecondes is very very important for the goal of my project !!! :) )

Thinks for all

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