Jump to content

Recommended Posts

Posted (edited)

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
Posted

If you want to query the headers of the request you can use _WinHttpQueryHeaders, take a look at the example from the help file:

  Reveal hidden contents

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.

Posted

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

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

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:

Posted

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

Posted

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)

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