coolboy9 Posted July 27, 2014 Share Posted July 27, 2014 (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 July 27, 2014 by coolboy9 Link to comment Share on other sites More sharing options...
trancexx Posted July 27, 2014 Author Share Posted July 27, 2014 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 .. wendbut 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 ), 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 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. tourism123 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
trancexx Posted July 27, 2014 Author Share Posted July 27, 2014 #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) coolboy9 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
tourism123 Posted July 27, 2014 Share Posted July 27, 2014 @trancexx, yeah, thank you Link to comment Share on other sites More sharing options...
coolboy9 Posted July 28, 2014 Share Posted July 28, 2014 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 Thank you very much Link to comment Share on other sites More sharing options...
coolboy9 Posted August 14, 2014 Share Posted August 14, 2014 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) Link to comment Share on other sites More sharing options...
Tjalve Posted August 21, 2014 Share Posted August 21, 2014 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: Link to comment Share on other sites More sharing options...
step887 Posted August 21, 2014 Share Posted August 21, 2014 $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 trancexx 1 Link to comment Share on other sites More sharing options...
Tjalve Posted August 22, 2014 Share Posted August 22, 2014 $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. Link to comment Share on other sites More sharing options...
RickB75 Posted October 2, 2014 Share Posted October 2, 2014 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. Link to comment Share on other sites More sharing options...
trancexx Posted October 2, 2014 Author Share Posted October 2, 2014 No. You are probably doing something else wrong. What's the rest of the code? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
RickB75 Posted October 3, 2014 Share Posted October 3, 2014 Trancexx, I figured out what my issue was with the PDF. I did have another question for you though. Is it ok if I PM you? Link to comment Share on other sites More sharing options...
RickB75 Posted October 3, 2014 Share Posted October 3, 2014 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? Link to comment Share on other sites More sharing options...
trancexx Posted October 3, 2014 Author Share Posted October 3, 2014 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 Link to comment Share on other sites More sharing options...
RickB75 Posted October 3, 2014 Share Posted October 3, 2014 Awesome! I just sent you a PM so I could go a little more in depth. Link to comment Share on other sites More sharing options...
RickB75 Posted October 3, 2014 Share Posted October 3, 2014 Trancexx I just figured it out!!! Link to comment Share on other sites More sharing options...
RickB75 Posted October 4, 2014 Share Posted October 4, 2014 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?? Link to comment Share on other sites More sharing options...
trancexx Posted October 4, 2014 Author Share Posted October 4, 2014 I don't know. Maybe the new content was appended in your tests. Really depends on your code, and I don't know what it looks like to say anything smarter. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Danyfirex Posted October 4, 2014 Share Posted October 4, 2014 I think your POST header is wrong. use some HTTP analizer. saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
RickB75 Posted October 6, 2014 Share Posted October 6, 2014 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?? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now