Jump to content

WinHTTP functions


trancexx
 Share

Recommended Posts

Hello,

I tryed not to post but I could not find the reason my short script is not working.

I'm trying to fill and submit a very simple form (secure) but the result I get is the same form page I started with, not the expected result page (as after pressing the submit button).

Could you help me, please?

My script:

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

; !!!Note that this example will fail because of invalid username and password!!!
; Use real data for authentication
Global $sUserName = "12345678909"
Global $sPassword = "11111970"
Global $sDomain = "ccd.serpro.gov.br"
Global $sPage = "correios/acecpfa1/solicitar.html"

Global $sAdditionalData = "cpF=" & $sUserName & "&nasC=" & $sPassword

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

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


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

; See what's returned
MsgBox(0, "Returned", $sReturned)
Link to comment
Share on other sites

@trancexx

_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
...
$hOpen2 = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen2, $sAddress)
_WinHttpSetOption($hOpen2, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_COOKIES)

Yes I already closed it and reopened in new Handle.

End result is the 1st file correctly filled (over 70kb) and I get there the ID ($p_Id)I need to get the 2nd URL.

Once i concatenate datas

$spage_2= $spage_2& $p_id

I get the full URL ($address + $page_2)

but when I process the POST request it ends as before also adding the string you suggested me.

Still 0 Bytes file...

Any hint?

Ty mate,

M.

Link to comment
Share on other sites

Yes I already closed it and reopened in new Handle.

Well, don't close $hOpen if you want to keep cookies. That handle have cookies.

WinHttpCloseHandle($hConnect)
;_WinHttpCloseHandle($hOpen)
...
;$hOpen2 = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, $sAddress)) ; the same $hOpen

@eson, ccd.serpro.gov.br/correios/acecpfa1/solicitar.html doesn't exist.

Link to comment
Share on other sites

Same result, 0 byte file.

I'll PVT you the original file with all my datas, so you can check yourself.

Forget about ";" and comments, it's just to test all the steps, but you will surely understand it well.

M.

Edited by marko001
Link to comment
Share on other sites

Same result, 0 byte file.

I'll PVT you the original file with all my datas, so you can check yourself.

Forget about ";" and comments, it's just to test all the steps, but you will surely understand it well.

M.

Your message was cut-off in the middle. I only got few lines of code.

But to make one thing clear if it's not; Ask for help with code, don't ask for code.

Your script must be runnable, I have no intention of fixing trivialities.

Link to comment
Share on other sites

Agreed, it's my intention to self-develop it, I personally think i can manage the code, I just miss some datas as I stated before.

I sent you the code working with my credentials, you can take a look and you can also post the solution (I think useful for the community) here.

Thanks again,

Marco

Link to comment
Share on other sites

  • 2 weeks later...

yo trancexx, prog@ndy !!

i've been reading entirely this thread 2-3 times

while trying on a piece of project using this wonderful WinHTTP UDF, I finally arrived to some result !!

and wanted to tell you that you guys rock !!!! I'm learning a lot through your pieces of code, examples, and UDF.

thats it

cheers!

hench

;)

Link to comment
Share on other sites

yo trancexx, prog@ndy !!

i've been reading entirely this thread 2-3 times

while trying on a piece of project using this wonderful WinHTTP UDF, I finally arrived to some result !!

and wanted to tell you that you guys rock !!!! I'm learning a lot through your pieces of code, examples, and UDF.

thats it

cheers!

hench

;)

okely-dokely

Just remember that recycling cans is important ...and other stuff like that. Go now and make us all proud. :)

Link to comment
Share on other sites

  • 2 weeks later...

I need same help..

I have to send the url above. This send a command to a openfire internal server to add an account.

I'm trying with _WinHttpSimpleSendSSLRequest, but it doesn't working...

URL:

"https://10.6.0.67:9091/plugins/userService/userservice?type=add&secret=7Kfs4nj3&username=teste&password=drowssap&name=franz&email=franz@kafka.com"

thanks

brejack

Link to comment
Share on other sites

Does anyone have an example of how to use this UDF to get the HTML or TEXT from a webpage that requires basic login credentials to access it..?

Just open the helpfile and read the entry for _WinHttpSetCredentials? :graduated:

*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

Is there any way to Change or Disable Keep-Alive Connections at all when using functions from this UDF..??

I googled for countless hours and came across these articles, but im not quite sure how to implement them into this UDF though..??

http://social.msdn.microsoft.com/Forums/en/vclanguage/thread/fb120cfe-bfae-400b-8675-74444f1910a5

http://www.geekpedia.com/Thread28023_Disabling-Keep-alive.html

Edited by cypher175
Link to comment
Share on other sites

Is there any way to Change or Disable Keep-Alive Connections at all when using functions from this UDF..??

I googled for countless hours and came across these articles, but im not quite sure how to implement them into this UDF though..??

http://social.msdn.microsoft.com/Forums/en/vclanguage/thread/fb120cfe-bfae-400b-8675-74444f1910a5

http://www.geekpedia.com/Thread28023_Disabling-Keep-alive.html

I don't see a problem with that. This works just fine for me (modified _WinHttpReadData.au3):

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

; Initialize
Global $hOpen = _WinHttpOpen()

If @error Then
    MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")
    Exit 1
EndIf

; Specify what to connect to
Global $hConnect = _WinHttpConnect($hOpen, "yahoo.com") ; <- yours here
If @error Then
    MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.")
    _WinHttpCloseHandle($hOpen)
    Exit 2
EndIf

; Create request
Global $hRequest = _WinHttpOpenRequest($hConnect)
If @error Then
    MsgBox(48, "Error", "Error creating an HTTP request handle.")
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 3
EndIf

;=======================================================================================
If _WinHttpSetOption($hRequest, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_KEEP_ALIVE) Then
    MsgBox(64, "Yes!", "Sucessfully modified KEEP_ALIVE feature.")
Else
    MsgBox(64, "Shit", "Something went wrong. Ah well...")
EndIf
;=======================================================================================

; Send it
_WinHttpSendRequest($hRequest)
If @error Then
    MsgBox(48, "Error", "Error sending specified request.")
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 4
EndIf

; Wait for the response
_WinHttpReceiveResponse($hRequest)

; See if there is data to read
Global $sChunk, $sData
If _WinHttpQueryDataAvailable($hRequest) Then
    ; Read
    While 1
        $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)

You?

edit: the result will be "Connection: Close"

I guess it can be done like this too:

_WinHttpAddRequestHeaders($hRequest, "Connection: Close", $WINHTTP_ADDREQ_FLAG_ADD)

So, I really don't see a problem. But of course I could be misunderstanding what you want to do.

Edited by trancexx
Link to comment
Share on other sites

wow thanks, I cant believe it was just a simple "Connection: Close" that I needed to use for the $sHeader option with "_WinHttpSimpleRequest()" to disable "Keep-Alives"...

So when using the "_WinHttpSimpleRequest()" function, how do you send more than one - Additional Headers Values for $sHeader..??

Also, How can I Specify a "Keep-Alive-Time-Out-Value" for the $sHeader Option..??

Link to comment
Share on other sites

So when using the "_WinHttpSimpleRequest()" function, how do you send more than one - Additional Headers Values for $sHeader..??

Separate them with @CRLF:

"Connection: Close" & @CRLF & "Referrer: something" & @CRLF & ...

Also, How can I Specify a "Keep-Alive-Time-Out-Value" for the $sHeader Option..??

Same thing:

"Keep-Alive: timeout=15"

edit: why do you use so much question marks? To express emotion or what?

???

Edited by trancexx
Link to comment
Share on other sites

  • 2 weeks later...

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