Jump to content
Sign in to follow this  
Darako

[Solved]How to capture a GET HTPP?

Recommended Posts

Darako

Hello,

I am writing a script but I have a problem... And I need your Help! :huh2:

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:

Posted Image

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

Share this post


Link to post
Share on other sites
Mithrandir

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.

Share this post


Link to post
Share on other sites
Mithrandir

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.

Share this post


Link to post
Share on other sites
Darako

Thanks for your post.

I try it tomorrow... :huh2:

Share this post


Link to post
Share on other sites
Darako

Hello,

Didn't work :huh2:

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

Share this post


Link to post
Share on other sites
jvanegmond

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

Share this post


Link to post
Share on other sites
Darako

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

Share this post


Link to post
Share on other sites
jvanegmond

HTTPS is different and probably won't work easily in this way.

Share this post


Link to post
Share on other sites
Darako

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

Share this post


Link to post
Share on other sites
Darako

It's a http connection and not a https connection! It's 80!

Share this post


Link to post
Share on other sites
Fly By Night

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

Share this post


Link to post
Share on other sites
Darako

Doesnt work, my $var is not an array... :/

Share this post


Link to post
Share on other sites
Fly By Night

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.

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

Share this post


Link to post
Share on other sites
Darako

Thank for your post.

I try it tomorrow!

Share this post


Link to post
Share on other sites
Darako

Oh yeah! It's ok!

I see the good header! I'm very happy! :huh2:

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
Sign in to follow this  

×