Jump to content

Recommended Posts

Posted

No, of course credentials can't be passed automatically.

Your browser saved credentials somewhere and passes them for domain (or whatever).

Okay, makes sense.  Thanks trancexx.

Posted

That script have _WinHttpWriteData() that is not in WinHTTP.au3 (I wasn't sure about "str" or "wstr" in dll call).          

the above code is useful ,thanks !!

  • 4 weeks later...
Posted

Question about connecting with winHTTP on non-standard ports for HTTP or on a localhost.

It seems I can connect to websites on my computer using winHTTP and GET/POST. But when I try to setup a web server on my local machine on a port such as 8884, it does not return any results.

Local $hconnection = _WinHttpConnect($hsession, "localhost:8884")

_WinHttpQueryDataAvailable($hrequest) just returns unavailable, and there is not data coming back from _WinHttpQueryHeaders and _WinHttpReadData.

But when I submit the same GET/POST request on something like POSTMAN Chrome extension, there is no problem access localhost or localhost on a non-standard HTTP port.

Is there something special I need to do in the _WinHttpConnect description of the local host?

Thanks in advance.

 

Posted

Question about connecting with winHTTP on non-standard ports for HTTP or on a localhost.

 

It seems I can connect to websites on my computer using winHTTP and GET/POST. But when I try to setup a web server on my local machine on a port such as 8884, it does not return any results.

 

Local $hconnection = _WinHttpConnect($hsession, "localhost:8884")

 

_WinHttpQueryDataAvailable($hrequest) just returns unavailable, and there is not data coming back from _WinHttpQueryHeaders and _WinHttpReadData.

 

But when I submit the same GET/POST request on something like POSTMAN Chrome extension, there is no problem access localhost or localhost on a non-standard HTTP port.

 

Is there something special I need to do in the _WinHttpConnect description of the local host?

 

Thanks in advance.

Yes, port number is third parameter for that function.

Just read description from the help file and pass port number as third argument.

♡♡♡

.

eMyvnE

Posted

Yes, port number is third parameter for that function.

Just read description from the help file and pass port number as third argument.

 

Ah... so very helpful. Very grateful.

That's a total miss on my part. A good rule: Read the documentation again :) Late night programming does that. Thank you again. 

  • 1 month later...
Posted
Hello, I have a problem.
I can not read this test page:
 
from googledrive with this example:
#include <Array.au3>

#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

Global $hOpen , $hConnect , $hRequest
; Initialize
$hOpen = _WinHttpOpen()


; Specify what to connect to
$hConnect = _WinHttpConnect($hOpen, "https://googledrive.com/host/0B-dsGBArc-IuVHdIRFFyUV8xSXc/host-in-drive.html") ; <- yours here

; Create request
$hRequest = _WinHttpOpenRequest($hConnect)

; Send it
_WinHttpSendRequest($hRequest)

; Wait for the response
_WinHttpReceiveResponse($hRequest)
;MsgBox(0,"","test")

; See if there is data to read
Global $sChunk, $sData
If _WinHttpQueryDataAvailable($hRequest) Then
    ; Read
    While 1
        ToolTip("test")
        $sChunk = _WinHttpReadData($hRequest)
        If @error Then ExitLoop
        $sData &= $sChunk
    WEnd
    ConsoleWrite($sData & @CRLF) ; print to console
Else
    MsgBox(48, "Error", "Site is experiencing problems.")
EndIf

; Close handles when they are not needed any more
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

I using WinHttp v1.6.3.7

it working only with "yahoo.com".

What's the problem?

Posted

You are calling it wrong. Just read functions' headers about parameters.

There is also help file in the package with plethora of examples, try some and work from there maybe.

♡♡♡

.

eMyvnE

Posted

You are calling it wrong. Just read functions' headers about parameters.

There is also help file in the package with plethora of examples, try some and work from there maybe.

You do not know how many times I tried to make it work without success before I comment here ..

I'd appreciate it if you at least point me to the right direction..

thanks

Posted

So anyway, in case you're still trying maybe this would help:

#include "WinHttp.au3"

$sDomain = "https://googledrive.com"
$sPage = "host/0B-dsGBArc-IuVHdIRFFyUV8xSXc/host-in-drive.html"

; Initialize and get session handle
$hOpen = _WinHttpOpen()
; Get connection handle
$hConnect = _WinHttpConnect($hOpen, $sDomain)

; SimpleSSL-request it...
$sReturned = _WinHttpSimpleSSLRequest($hConnect, Default, $sPage)

; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; See what's returned
MsgBox(0, "Returned", $sReturned)

♡♡♡

.

eMyvnE

Posted (edited)

 

So anyway, in case you're still trying maybe this would help:

#include "WinHttp.au3"

$sDomain = "https://googledrive.com"
$sPage = "host/0B-dsGBArc-IuVHdIRFFyUV8xSXc/host-in-drive.html"

; Initialize and get session handle
$hOpen = _WinHttpOpen()
; Get connection handle
$hConnect = _WinHttpConnect($hOpen, $sDomain)

; SimpleSSL-request it...
$sReturned = _WinHttpSimpleSSLRequest($hConnect, Default, $sPage)

; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; See what's returned
MsgBox(0, "Returned", $sReturned)

Thank you.

You would not need to bother .. I was going to try what you said anyway. I just took a break.

I will test it.

I don't like the point that if the url is in https protocol then i should call it a different way.

I would prefer a function that get URL - no matter if it is http or https and then gives the output, which is the downloaded data.

I don't know how much it is complex to write a function that only decides how to call to the function based on the type of the URL.

I guess it's an easy thing to do.

so if i will decide to use your UDF, I'll try to do it

Edited by Guest
Posted (edited)

 

So anyway, in case you're still trying maybe this would help:

#include "WinHttp.au3"

$sDomain = "https://googledrive.com"
$sPage = "host/0B-dsGBArc-IuVHdIRFFyUV8xSXc/host-in-drive.html"

; Initialize and get session handle
$hOpen = _WinHttpOpen()
; Get connection handle
$hConnect = _WinHttpConnect($hOpen, $sDomain)

; SimpleSSL-request it...
$sReturned = _WinHttpSimpleSSLRequest($hConnect, Default, $sPage)

; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; See what's returned
MsgBox(0, "Returned", $sReturned)

 

Can you please give an example how to do it during a loop without stopping the script?

I don't know if this is the correct way to do it:

#include "WinHttp.au3"



$sDomain = "https://googledrive.com"
$sPage = "host/0B-dsGBArc-IuVHdIRFFyUV8xSXc/host-in-drive.html"

; Initialize and get session handle
$hOpen = _WinHttpOpen()
; Get connection handle
$hConnect = _WinHttpConnect($hOpen, $sDomain)

; SimpleSSL-request it...
;~ $sReturned = _WinHttpSimpleSSLRequest($hConnect, Default, $sPage)
$timer0 = TimerInit()
$test = _WinHttpSimpleSendSSLRequest($hConnect,Default,$sPage)
ConsoleWrite(TimerDiff($timer0)&@CRLF)

$timer = TimerInit()
While 1
    ToolTip("test")
    If TimerDiff($timer) > 5000 Then ExitLoop
    If _WinHttpQueryDataAvailable($test) = 1 Then
        ConsoleWrite(_WinHttpReadData($test)&@CRLF)
        ExitLoop
    EndIf

WEnd

; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; See what's returned

According to my test, this is not the right way ...

Edited by Guest
Posted (edited)

Then you read inside the (main) script loop with _WinHttpReadData specifying the size of read data (third parameter of the function).

 

but it takes about 600ms - 1000ms for line:

$test = _WinHttpSimpleSendSSLRequest($hConnect,Default,$sPage)

to finish.

is it normal?

I think it happens because this function is waiting for the page to finish load..

this code proves my point.

#include "WinHttp.au3"


$sDomain = "https://googledrive.com"
$sPage = "host/0B-dsGBArc-IuVHdIRFFyUV8xSXc/host-in-drive.html"

; Initialize and get session handle
$hOpen = _WinHttpOpen()
; Get connection handle
$hConnect = _WinHttpConnect($hOpen, $sDomain)

; SimpleSSL-request it...
;~ $sReturned = _WinHttpSimpleSSLRequest($hConnect, Default, $sPage)
$timer0 = TimerInit()
$test = _WinHttpSimpleSendSSLRequest($hConnect,Default,$sPage)
ConsoleWrite(TimerDiff($timer0)&@CRLF)

ConsoleWrite(_WinHttpReadData($test)&@CRLF)

; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; See what's returned

It works without a loop .. it means that the function is waiting until the page is fully loaded

Edited by Guest
Posted (edited)

It means connecting to the site and waiting for it to reply to your request takes that time.

yes. but at that time i need that the script will keep working.. 600ms-1000ms is bad because my script connects to more than one url.

so i need that this part  of loading & connecting the urls and downloading the data will occur in background.

is this possible with your UDF with HTTPS?

if so then please give me an example of downloading a page into a variable in background from HTTPS url.

thanks

Edited by Guest
Posted (edited)

Sorry that  I do not understand how to use this UDF.
for some reason, it's the only UDF I could not figure out how to use it properly after many attempts to figure out how to do what I want ..

I'll keep trying to figure out how to use it

Edited by Guest
Posted

Sorry that  I do not understand how to use this UDF.

Erm ... this is one of the best well documented UDFs I know that isn't part of AutoIt.

My new saying is "lack of code, lack of trying!"

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Posted

No matter, I see that I'm not the only one who wanted to do it. I see someone else asked the same thing here. I probably missed it .. There's a lot of pages here.

Anyway, I think I got the answer.
 

EDIT:

Ok, tested the answer that i found in >#427

And that example is working.

I understand that the example shows how to do it in the background.

But the problem is that this part in the example:

$sUrl = 'https://www.magroup-online.com/IBA/ES/ES/IBA_ES_es_PaymentSecurity.html'
$hOpen = _WinHttpOpen()
$aCrackedUrl = _WinHttpCrackUrl ( $sUrl )
$hConnect = _WinHttpConnect($hOpen, $aCrackedUrl[2], $INTERNET_DEFAULT_HTTPS_PORT)
$hRequest = _WinHttpOpenRequest($hConnect, Default, $aCrackedUrl[6], Default, Default, Default, $WINHTTP_FLAG_SECURE)
_WinHttpSendRequest($hRequest)
_WinHttpReceiveResponse($hRequest)

Takes about 500ms-700ms to finish - And this fact makes it not really background..

I mean - i know that after this part is finish, the rest of the action is occurs is in background(when the loop is active)

but before that loop, the operation works too slowly and i can't call it "in background" because it is slow..

this for example:

$timer = TimerInit()
InetGet('https://www.magroup-online.com/IBA/ES/ES/IBA_ES_es_PaymentSecurity.html',"test",Default,1)
ConsoleWrite(TimerDiff($timer)&@CRLF)

Is something that takes very short time to finish. it takes 5ms - 8ms.

This is the time that i would expect from the first code..

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
  • Recently Browsing   0 members

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