Darako Posted June 16, 2011 Share Posted June 16, 2011 (edited) Hello,I am writing a script but I have a problem... And I need your Help! I use winhttp.au3 for download file in the internet$source = _WinHttpConnect($hOpen,$website) $file = _WinHttpSimpleRequest($source,Default,$Link) msgbox(0,"",$file)The msgbox it's ok, I see my txt file, but I dont know the name of the txt... I did a capture with wireshark, I show the resultat:I want know the second or third http request who contains the name of my txt... But I dont know how to do... I tryed to use TCPSend/Recv but it sends only TCP and not HTPP... Then I tryed to use Winpcap.au3 but I cant capture and use _WinHttpSimpleRequest...There is a solution?Thank in advance! Edited June 20, 2011 by Darako Link to comment Share on other sites More sharing options...
Mithrandir Posted June 16, 2011 Share Posted June 16, 2011 If you want to query the headers of the request you can use _WinHttpQueryHeaders, take a look at the example from the help file: #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include "WinHttp.au3" Opt("MustDeclareVars", 1) ; Open needed handles Global $hOpen = _WinHttpOpen() Global $hConnect = _WinHttpConnect($hOpen, "msdn.microsoft.com") ; Specify the reguest: Global $hRequest = _WinHttpOpenRequest($hConnect, Default, "en-us/library/aa384101(VS.85).aspx") ; Send request _WinHttpSendRequest($hRequest) ; Wait for the response _WinHttpReceiveResponse($hRequest) Global $sHeader ; If there is data available... If _WinHttpQueryDataAvailable($hRequest) Then $sHeader = _WinHttpQueryHeaders($hRequest) ; ...get full header ; Clean _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; Display retrieved header MsgBox(0, "Header", $sHeader) Then you can use regexp to search for the name of the file. You said it's a .txt so you can search for a string that finishes in .txt for instance. Help with SOAP message!! Link to comment Share on other sites More sharing options...
Mithrandir Posted June 16, 2011 Share Posted June 16, 2011 Wait, you can just use _WinHttpSimpleRequest with $fGetHeaders = True . In that case the function returns an array which has the headers in the first cell. Help with SOAP message!! Link to comment Share on other sites More sharing options...
Darako Posted June 16, 2011 Author Share Posted June 16, 2011 Thanks for your post. I try it tomorrow... Link to comment Share on other sites More sharing options...
Darako Posted June 17, 2011 Author Share Posted June 17, 2011 Hello, Didn't work When I try the first solution, MsgBox show the header of my first request and I dont see the header of my second or third request... When I try the second solution: $file = _WinHttpSimpleRequest($source,Default,$Link,Default,Default,Default,True) ; Return values .: Success - response data if $fGetHeaders = False (default) ; |Array if $fGetHeaders = True ; | [0] - response headers ; | [1] - response data But $file is not array... /: and i see response data... Link to comment Share on other sites More sharing options...
jvanegmond Posted June 17, 2011 Share Posted June 17, 2011 HTTP is a protocol that uses TCP. If you are already familiar with Wireshark you will find it easy to recreate the behavior of your browser for example. Simply do something like below: TCPStartup() $sPacket = "GET / HTTP/1.1" & @CRLF & "Host: yourlink" & @CRLF & @CRLF $iSocket = TCPConnect("ip here", 80) TCPSend($iSocket, $sPacket) ; capture output github.com/jvanegmond Link to comment Share on other sites More sharing options...
Darako Posted June 17, 2011 Author Share Posted June 17, 2011 (edited) Thanks for your post. I dont understand, didnt work it. I did my TcpSend request with Autoit, my http subsections are identical but my tcpsend request dont receive answer... I can see difference only in TCP subction... I didnt see why didnt work it... :/ Edited June 17, 2011 by Darako Link to comment Share on other sites More sharing options...
jvanegmond Posted June 17, 2011 Share Posted June 17, 2011 HTTPS is different and probably won't work easily in this way. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Darako Posted June 17, 2011 Author Share Posted June 17, 2011 Sorry, but it's http and not HTTPS! I edited my last post. I did an other attempt... I use this: $Packet = Binary("0x.........................") TCPStartUp() $Connection = TCPConnect($IP, 80 ) TCPSend($Connection,$Packet) In Binary I use an hexadecimal code that I recovered with a good request whom normally have an answer... But it doesnt work... Link to comment Share on other sites More sharing options...
jvanegmond Posted June 17, 2011 Share Posted June 17, 2011 (edited) Try $Connection = TCPConnect($IP, 443 ) HTTP = 80 HTTPS = 443 Edited June 17, 2011 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
Darako Posted June 17, 2011 Author Share Posted June 17, 2011 It's a http connection and not a https connection! It's 80! Link to comment Share on other sites More sharing options...
Fly By Night Posted June 17, 2011 Share Posted June 17, 2011 Use Mithrandir's code from post #2 and add this after $hOpen = _WinHttpOpen() _WinHttpSetOption($hOpen, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REDIRECT_POLICY_NEVER) Just turns off server redirects. You can then extract the Location value from the headers returned in $sHeader Link to comment Share on other sites More sharing options...
Darako Posted June 18, 2011 Author Share Posted June 18, 2011 Doesnt work, my $var is not an array... :/ Link to comment Share on other sites More sharing options...
Fly By Night Posted June 18, 2011 Share Posted June 18, 2011 This is my code i used for this. Normally you get redirected to the final location of u.to/6GECAQ. By adding that WinHttpSetOption line, i stop redirects then you can grab the location it is going to by extracting Location: from the headers. expandcollapse popup#include "WinHttp.au3" $host = "u.to" $hGet = "/6GECAQ" ; Initialize and get session handle Global $hOpen = _WinHttpOpen() _WinHttpSetOption($hOpen, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REDIRECT_POLICY_NEVER) ; Get connection handle Global $hConnect = _WinHttpConnect($hOpen, $host) ; Request Global $hRequest = _WinHttpOpenRequest($hConnect, "GET", $hGet) _WinHttpSendRequest($hRequest) _WinHttpReceiveResponse($hRequest) Global $sHeader ; If there is data available... If _WinHttpQueryDataAvailable($hRequest) Then $sHeader = _WinHttpQueryHeaders($hRequest) ; ...get full header ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) MsgBox(0, "Header", $sHeader) Link to comment Share on other sites More sharing options...
Darako Posted June 19, 2011 Author Share Posted June 19, 2011 Thank for your post. I try it tomorrow! Link to comment Share on other sites More sharing options...
Darako Posted June 20, 2011 Author Share Posted June 20, 2011 Oh yeah! It's ok! I see the good header! I'm very happy! 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