Jump to content

WinHTTP functions


trancexx
 Share

Recommended Posts

Hey ProgAndy,

There is another minor bug in the WinHTTP.au3.

Take a look at _WinHttpSimpleRequest() and _WinHttpSimpleSSLRequest().

In both functions you can find a line like this:

If $fGetHeaders = Default Or $fGetHeaders = -1 Then $fGetHeaders = False

In case $fGetHeaders is 'True' by the time this line gets executed, AutoIt changes it to 'False' again, because -1 is True. (Everything except 0 and "" is true, as you probably know).

$fGetHeaders = True
If $fGetHeaders = -1 Then MsgBox(0, "", "-1 is True")

The workaround is to use "0" or "1" for the $fGetHeaders-parameter when calling the function. Guess it should be called $iGetHeaders then, huh?

Just wanted to let you know that.

Edited by SEuBo
Link to comment
Share on other sites

Hey ProgAndy,

There is another minor bug in the WinHTTP.au3.

Take a look at _WinHttpSimpleRequest() and _WinHttpSimpleSSLRequest().

In both functions you can find a line like this:

If $fGetHeaders = Default Or $fGetHeaders = -1 Then $fGetHeaders = False

In case $fGetHeaders is 'True' by the time this line gets executed, AutoIt changes it to 'False' again, because -1 is True. (Everything except 0 and "" is true, as you probably know).

$fGetHeaders = True
If $fGetHeaders = -1 Then MsgBox(0, "", "-1 is True")

The workaround is to use "0" or "1" for the $fGetHeaders-parameter when calling the function. Guess it should be called $iGetHeaders then, huh?

Just wanted to let you know that.

Shit, you were faster... :huh2: Wanted to report this too.

EDIT: It isn't a line like this, it is exactly this line.

Edited by Simon1602
Link to comment
Share on other sites

Its seemss like the function send the data not in the right order..

I'm using tcp spy.

and I'm trying to copy a http request...

http://registration.orange.co.il/copa/pages/protected/protectedredirect.aspx?original=http%3a%2f%2fwww.orange.co.il%2fhe-il%2fcellular%2f

GET /copa/pages/protected/protectedredirect.aspx?original=http%3a%2f%2fwww.orange.co.il%2fhe-il%2fcellular%2f HTTP/1.1
Host: registration.orange.co.il
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive

But its seems that the data isnt sent in the right order...

GET /copa/pages/protected/protectedredirect.aspx?original=http%3a%2f%2fwww.orange.co.il%2fhe-il%2fcellular%2f HTTP/1.1
Connection: Keep-Alive
Keep-Alive: 115
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: gzip,deflate
Accept-Language: en-us,en;q=0.5
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17
Host: registration.orange.co.il

My code is

$A=_WinHttpOpen()
$B = _WinHttpConnect($A,"registration.orange.co.il")
$C = _WinHttpOpenRequest($B,"GET","/copa/pages/protected/protectedredirect.aspx?original=http%3a%2f%2fwww.orange.co.il%2fhe-il%2fcellular%2f")
_WinHttpAddRequestHeaders($C,"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17")

_WinHttpAddRequestHeaders($C,"Connection: keep-alive")

_WinHttpAddRequestHeaders($C,"Keep-Alive: 115")
_WinHttpAddRequestHeaders($C,"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7")
_WinHttpAddRequestHeaders($C,"Accept-Encoding: gzip,deflate")
_WinHttpAddRequestHeaders($C,"Accept-Language: en-us,en;q=0.5")
_WinHttpAddRequestHeaders($C,"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")







_WinHttpSendRequest($C)
_WinHttpReceiveResponse($C)
$t=_WinHttpQueryHeaders($C)
ConsoleWrite($t)
 $AB = _WinHttpReadData($C)
 ConsoleWrite($AB)
 Exit

and its not working anyway..

I'm trying to make a program that will automatically send me a e-mail when I get a error...

Soo I'm trying to log in... But its not working.

Link to comment
Share on other sites

Remove _WinHttpAddRequestHeaders($C,"Accept-Encoding: gzip,deflate") line.

User-Agent is unnecessary, too. If you want to send a specific agent, set it in _WinHttpOpen.

Connection: Keep-Alive, Keep-Alive: 115 is also not required.

PS: data has to be read in a loop or with _WinHttpSimpleReadData.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

My code is

$A=_WinHttpOpen()
$B = _WinHttpConnect($A,"registration.orange.co.il")
$C = _WinHttpOpenRequest($B,"GET","/copa/pages/protected/protectedredirect.aspx?original=http%3a%2f%2fwww.orange.co.il%2fhe-il%2fcellular%2f")
_WinHttpAddRequestHeaders($C,"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17")

_WinHttpAddRequestHeaders($C,"Connection: keep-alive")

_WinHttpAddRequestHeaders($C,"Keep-Alive: 115")
_WinHttpAddRequestHeaders($C,"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7")
_WinHttpAddRequestHeaders($C,"Accept-Encoding: gzip,deflate")
_WinHttpAddRequestHeaders($C,"Accept-Language: en-us,en;q=0.5")
_WinHttpAddRequestHeaders($C,"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")

_WinHttpSendRequest($C)
_WinHttpReceiveResponse($C)
$t=_WinHttpQueryHeaders($C)
ConsoleWrite($t)
 $AB = _WinHttpReadData($C)
 ConsoleWrite($AB)
 Exit

and its not working anyway..

I'm trying to make a program that will automatically send me a e-mail when I get a error...

Soo I'm trying to log in... But its not working.

I don't have time to reproduce your code but meanwhile you can try putting a Msgbox(0,'error?',@error) between each line to see where errors are if any. Also, instead of
$B = _WinHttpConnect($A,"registration.orange.co.il")
I would try
$B = _WinHttpConnect($A,"www.registration.orange.co.il")

PS: Unless you used that names for this example, I would suggest using more mnemotechnic names for variables.

Edited by Mithrandir
Link to comment
Share on other sites

  • 5 weeks later...

Hello,

I'm trying to fill out two pages.

My AutoIt Code:

#include <WinHttp.au3>

Global $hOpen = _WinHttpOpen()
Global $hConnect = _WinHttpConnect($hOpen, "test.com")
Global $sRead1 = _WinHttpSimpleFormFill($hConnect, Default, Default, "name:pname", "John Doe")
FileWrite("sRead1.txt", $sRead1) ;~ successful - I get the HTML source from the next page.

Global $sRead2 = _WinHttpSimpleFormFill($hConnect, "/sendid.php", Default, "name:id", "22222")
If @error Then ConsoleWrite(@error & @CRLF) ;~ @error = 1
FileWrite("sRead2.txt", $sRead2) ;~ failed - sRead2.txt is empty.

_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

The first step ($sRead1) is working great.

But if I try to fill out the following page ($sRead2) it doesn't work anymore and the @error-code is: 1.

uhmmm... "No forms on the page"?

This is the sRead1.txt from the first Step:

<div>Test-Page:<br /><br />
ID-11111<br />
ID-22222<br />
ID-33333<br /><br />

<form action="sendid.php" method="post" enctype="multipart/form-data">Personal ID:<br />
<input type="text" name="id" value="11111" />
<input type="hidden" name="pname" value="John Doe" />
<input type="submit" value="Send" /></form></div>

Please can you point out my mistake?

Edited by MilkyWay
Link to comment
Share on other sites

Hello,

I'm trying to fill out two pages.

My AutoIt Code:

#include <WinHttp.au3>

Global $hOpen = _WinHttpOpen()
Global $hConnect = _WinHttpConnect($hOpen, "test.com")
Global $sRead1 = _WinHttpSimpleFormFill($hConnect, Default, Default, "name:pname", "John Doe")
FileWrite("sRead1.txt", $sRead1) ;~ successful - I get the HTML source from the next page.

Global $sRead2 = _WinHttpSimpleFormFill($hConnect, "/sendid.php", Default, "name:id", "22222")
If @error Then ConsoleWrite(@error & @CRLF) ;~ @error = 1
FileWrite("sRead2.txt", $sRead2) ;~ failed - sRead2.txt is empty.

_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

The first step ($sRead1) is working great.

But if I try to fill out the following page ($sRead2) it doesn't work anymore and the @error-code is: 1.

uhmmm... "No forms on the page"?

This is the sRead1.txt from the first Step:

<div>Test-Page:<br /><br />
ID-11111<br />
ID-22222<br />
ID-33333<br /><br />

<form action="sendid.php" method="post" enctype="multipart/form-data">Personal ID:<br />
<input type="text" name="id" value="11111" />
<input type="hidden" name="pname" value="John Doe" />
<input type="submit" value="Send" /></form></div>

Please can you point out my mistake?

Verify that sendid.php exists.

Btw, "test.com" is valid address. If you used it as placeholder for the actual server then next time make sure it doesn't exist in reality, to avoid misunderstandings.

Edited by trancexx
Link to comment
Share on other sites

Hi, thanks for your reply.

There are only 3 pages.

They are reachable in this order:

1. default/root (to enter the Name)

2. sendid.php (to enter the ID)

3. status.php (to receive the status)

I tried:

Global $sRead2 = _WinHttpSimpleFormFill($hConnect, "/sendid.php", "index:0", "name:id", "22222") ;~ also "index:1", "index:2", "index:3"
Global $sRead2 = _WinHttpSimpleFormFill($hConnect, "/status.php", "index:0", "name:id", "22222") ;~ also "index:1", "index:2", "index:3"

and sorry for my test.com example.

Link to comment
Share on other sites

  • 1 month later...

deltarocked if you had searched the forum you would've found this >>

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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

yup , I had seen that link two days ago , for some reason I chose not to use (as of this moment I do not remember why). but while scrounging through the help files i came across this :_WinHTTPReadDataAsync()

Case $WINHTTP_CALLBACK_STATUS_REDIRECT

$sStatus = "An HTTP request is about to automatically redirect the request."

ConsoleWrite(_WinHttpQueryHeaders($hInternet) & @CRLF)

Result:

>> Waiting for the server to respond to a request.

>> Successfully received a response from the server.

>> HTTP/1.1 301 Moved

Server: nginx

Date: Fri, 02 Sep 2011 12:02:35 GMT

Content-Type: text/html; charset=utf-8

Connection: keep-alive

Set-Cookie: _bit=4e60c5db-0028c-0325d-caac8fa8;domain=.j.mp;expires=Wed Feb 29 07:02:35 2012;path=/; HttpOnly

Cache-control: private; max-age=90

Location: http://F.q.d.n/p/a/t/h.htm

MIME-Version: 1.0

Content-Length: 150

This holds true for server based redirects but not for script based which require additional processing by a script enabled browser.

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