Jump to content

Recommended Posts

Posted (edited)

#include "WinHttp.au3"
$session = _WinHttpOpen("User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0")
$connect = _WinHttpConnect($session, "up.4share.vn")
$html = _WinHttpSimpleFormFill($connect, "?http://up.4share.vn/index/login", "login", "username", "vvhite", "Password", "123123")
FileWrite("Server 4Share Menu.html", $html)
_WinHttpCloseHandle($connect)
_WinHttpCloseHandle($session)

The above code I use to log on to my account page http://up.4share.vn but it failed
Please help
Thank you very much
Edited by coolboy9
Posted

Hi @trancexx,

I'm trying to run WinHttp without waitting (because WinHttp that causes to lag my GUI, WinHttp wait for the response by _WinHttpReceiveResponse).

I think i have 2 way to do that:

1, Non ASYNC mode, i try put  _WinHttpReceiveResponse in Func __WINHTTP_STATUS_CALLBACK, like ASYNC mode, but it don't work, why?

2, ASYNC mode, i use example in _WinHttpSimpleReadDataAsync. I add a second request below code MsgBox (*dummy code for waiting*). when i run it:

sendrequest_1
msgbox(0,"",""); Some dummy code for waiting
sendrequest_2
+>While first request doesn't finish, if i press ok in msgbox (continue with second request), script will crash.

+>If i wait first request done ($WINHTTP_CALLBACK_STATUS_READ_COMPLETE return) and after that press ok, script will run correctly.

So i check request finish by add var "$data_available = True" in case $WINHTTP_CALLBACK_STATUS_READ_COMPLETE

 and don't use msgbox, like that:

while 1
..
   if $abc=true then
       sendrequest_1
   endif 
   if $data_available=true then
       sendrequest_2
       ...
   endif
..
wend
but my script still crash.

is this problem "another or the same callback is called and the old hasn't finished, it will interrupt the old callback, too and execute itself"??!

i also try volatile Func __WINHTTP_STATUS_CALLBACK?? (i don't know i use it for what :D ), and nothing changes except the script crash without notice "Variable used without being declared."..

i hope you can understand what I write, my english is so bad :wacko:

Thanks for your time to read it. :)

Current official AutoIt callback function implementation unfortunately can't handle re-entrancy, as you have noticed. I made a remark about that in function description.

Good news is that other interpreters for AutoIt exist. For example, I was presented with one such just the other day. It works by compiling AutoIt code to real executable code. As a consequence stuff like this work. Until the author decides to publish it, I have no particularly smart advice.

♡♡♡

.

eMyvnE

Posted

#include "WinHttp.au3"
$session = _WinHttpOpen("User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0")
$connect = _WinHttpConnect($session, "up.4share.vn")
$html = _WinHttpSimpleFormFill($connect, "?http://up.4share.vn/index/login", "login", "username", "vvhite", "Password", "123123")
FileWrite("Server 4Share Menu.html", $html)
_WinHttpCloseHandle($connect)
_WinHttpCloseHandle($session)
The above code I use to log on to my account page http://up.4share.vn but it failed

Please help

Thank you very much

 

 

It should probably be more like this:

#include "WinHttp.au3"
$session = _WinHttpOpen("User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0")
$connect = _WinHttpConnect($session, "up.4share.vn")
$html = _WinHttpSimpleFormFill($connect, "/index/login", Default, "username", "vvhite", "Password", "123123")
;...
_WinHttpCloseHandle($connect)
_WinHttpCloseHandle($session)

♡♡♡

.

eMyvnE

Posted

 

It should probably be more like this:

#include "WinHttp.au3"
$session = _WinHttpOpen("User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0")
$connect = _WinHttpConnect($session, "up.4share.vn")
$html = _WinHttpSimpleFormFill($connect, "/index/login", Default, "username", "vvhite", "Password", "123123")
;...
_WinHttpCloseHandle($connect)
_WinHttpCloseHandle($session)

 

@trancexx,

yeah, thank you  :wub:

Thank you very much

  • 3 weeks later...
Posted

Hi!!

Can help me fix code, i don't Bug Fix, Thank very much !

#include "WinHttp.au3"
$session = _WinHttpOpen("User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0")
$connect = _WinHttpConnect($session, "upfile.vn")
$html = _WinHttpSimpleFormFill($connect, "http://upfile.vn/#Login", Default, "Act=Login&Email=", "a607374@trbvm.com", "&Password=", "123456")
FileWrite("Upfile.html", $html)
_WinHttpCloseHandle($connect)
_WinHttpCloseHandle($session)
Posted

Hi. I use this UDF to send data using HTTP POST. The idee is to send CSV TEXT data in a POST request and the server then creates a CSV file on the server. For security reasons i create a md5 hash to go along with the data. The server adress and the hash has been changed in the example below.

This works GREAT! However i cant get it to work when the client connects to the internet trogh a proxy. So my question is. How can i use a awebbproxy to send POST requests using this UDF? Any help would be appritiated.

$adress = "serveradress"
$path = "/api/uploadcsv"
$data = "Testar Webbservice!"
$filename = "testfil.dat"
$data_enc = _httpencodestring($data)
$httpobject = _WinHttpOpen()
$connection = _WinHttpConnect($httpobject, $adress,80)
$description = _httpencodestring($filename)
$hash = _httpencodestring(md5($data & $filename & "hashpassword"))
$hRequest = _WinHttpSimpleSendRequest($connection, "POST", $path,Default,"data=" & $data_enc & "&description=" & $description & "&md5sum=" & $hash)
$answer = _WinHttpSimpleReadData($hRequest)
ConsoleWrite($answer & @CRLF) 

This is great stuff!!
However im having one issue.
 
I have a simple webbservice that take POST data witch is send using a specific M5 hash, and creates a CSv file on the server. That way i can use my script to "send" csv files to the server over the internet. This works great. I simply use this code to send the POST request:

Posted

$httpobject = _WinHttpOpen(Default,$WINHTTP_ACCESS_TYPE_DEFAULT_PROXY)

Retrieves the static proxy or direct configuration from the registry. WINHTTP_ACCESS_TYPE_DEFAULT_PROXY does not inherit browser proxy settings. WinHTTP does not share any proxy settings with Internet Explorer.

The WinHTTP proxy configuration is set by one of these mechanisms.
The proxycfg.exe utility on Windows XP and Windows Server 2003 or earlier.
The netsh.exe utility on Windows Vista and Windows Server 2008 or later.
WinHttpSetDefaultProxyConfiguration on all platforms.
 
httpobject = _WinHttpOpen(Default,$WINHTTP_ACCESS_TYPE_NAMED_PROXY,'www.proxy.com:8080')

If you wanted to specify a proxy

Posted
$httpobject = _WinHttpOpen(Default,$WINHTTP_ACCESS_TYPE_DEFAULT_PROXY)

Retrieves the static proxy or direct configuration from the registry. WINHTTP_ACCESS_TYPE_DEFAULT_PROXY does not inherit browser proxy settings. WinHTTP does not share any proxy settings with Internet Explorer.

The WinHTTP proxy configuration is set by one of these mechanisms.
The proxycfg.exe utility on Windows XP and Windows Server 2003 or earlier.
The netsh.exe utility on Windows Vista and Windows Server 2008 or later.
WinHttpSetDefaultProxyConfiguration on all platforms.
 
httpobject = _WinHttpOpen(Default,$WINHTTP_ACCESS_TYPE_NAMED_PROXY,'www.proxy.com:8080')

If you wanted to specify a proxy

 

Awsome. Thank you so mutch. I will test it. Thank you.

  • 1 month later...
Posted

Does saving a PDF require additional steps other than this:

Global $bChunk, $bData, $hFile
If _WinHttpQueryDataAvailable($hHttpRequest) Then
    While 1
        $bChunk = _WinHttpReadData($hHttpRequest, 2) ; read binary
        If @error Then ExitLoop
        $bData = _WinHttpSimpleBinaryConcat($bData, $bChunk) ; concat two binary data
    WEnd
    ; Save it to the file
    $hFile = FileOpen($sDestination, 26)
    FileWrite($hFile, $bData)
    FileClose($hFile)
Else
    MsgBox(48, "Error occurred", "No data available. " & @CRLF)
EndIf

I keep getting an error when I try to open the pdf after it was saved. 

Posted

Trancexx,

      Maybe I don't need to PM. I'll give you a brief walk through with my issue and maybe you can guide me on what I need to do. I'm trying to download a PDF from a server. 

I'll tell you what I get when I do this using a browser and using the winHttp udf. 

Broswer:

I type in the direct url for the pdf. 

A login page comes up. 

I enter my login credentials and It appears I'm directly taken to the PDF.

Using Dev Tools though, theres  a total of 3 urls that get passed. Two redirects and the last is my PDF page. 

1st URL is an auth_cred_submit

2nd URL is a URL that contains a cookie and redirect info for my PDF page.

3rd URL is my PDF. 

 

winHttp UDF:

Using the PDF URL

I can connect, fill in the form and I get a response of "This page doesn't exist" returned back. 

Using the URL with the cookie in it.

I comment out the "Simple Form Fill" info. I can go directly to the PDF, download it to my pc and it works great. The cookies are set to expire after 4 hrs. 

 

I'm pretty sure I need to get the URL with the cookie in it. I don't know how to get it. Can you give advice on how to do this?

Posted

You don't need cookies manually set, that's for sure. Cookies are session properties, once you login tey are automatically passed with requests. If the server requires authencation, then credentials need to be added allways. Form filling function can pass credentials for you, just add them as last argument for it (help file gives more info).

Can I try? PM me whatever I should know if it's sensitive subject for you.

♡♡♡

.

eMyvnE

Posted

Trancexx,

      I did have a quick question. Now that I have my script working, I'm getting extra large file sizes with my downloads. If I use IE to download, the file size is 288 KB. When I use winHttp, the filesize is 3,212 KB for the same file. Also, I noticed as I loop through and download the PDF  files using winHTTP, the files vary in size quite a bit. 290 KB up to 3,212 KB. Normally they may be a couple hundred KB's diff in size. 

Do you have any idea why it's doing this??

Posted
Posted

Quick question: 

I have a loop in my main script. Basically the script works like this. I get a list of File Names from my server. I use an arraySearch to check for missing files. If there's a file missing, I use winHTTP to connect to the server, SimpleFormFill and then SendRequest. I query the Headers to make sure the content type is a PDF. Once that happens I use

; Wait for the response
_WinHttpReceiveResponse($hHttpRequest)
; Read if available
Global $bChunk, $bData, $hFile
If _WinHttpQueryDataAvailable($hHttpRequest) Then
    While 1
        $bChunk = _WinHttpReadData($hHttpRequest, 2) ; read binary
        If @error Then ExitLoop
        $bData = _WinHttpSimpleBinaryConcat($bData, $bChunk) ; concat two binary data
    WEnd
    ; Save it to the file
    $hFile = FileOpen($sDestination, 26)
    FileWrite($hFile, $bData)
    FileClose($hFile)
Else
    MsgBox(48, "Error occurred", "No data available. " & @CRLF)
EndIf

to save the PDF. For each missing PDF, I go through the entire connection, login and deconnection process. What's happening is each time the script saves a pdf, the file size gets larger. Example: the first file it save may be 266KB and the last one may be 5500KB. I don't understand why the file sizes are going up in size for basically the same files. Do I have to reconnect each time??

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