Jump to content
trancexx

WinHTTP functions

Recommended Posts

Are people still working on the async mode? I would love this to work without problem.

Everytime I execute one of the samples it always crashes randomly at different places.

New production AutoIT with Win7 x86.

Share this post


Link to post
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.

Edited by SEuBo

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I dont know why But the data I get back from the website is seen in scite is

US<BS

post-35491-0-31561000-1308587460_thumb.j

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

plz

;send data
$data_post="ナー"  ;Japanese
_WinHttpSendRequest($hRequest,"", $data_post)
_WinHttpReceiveResponse($hRequest)

not working

data = "ナ ."

plz fix ,see add-on "Live http header"

$data_post="%26%2312490%3B"

Share this post


Link to post
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?

Edited by MilkyWay

Share this post


Link to post
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

♡♡♡

.

eMyvnE

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...