Jump to content

Recommended Posts

Posted (edited)

#include <IE.au3>
#include <Winhttp.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <StringConstants.au3>
#include <Winhttp.au3>
#include <String.au3>
    TCPStartup()

    Local $iLocalSocket = TCPListen("127.0.0.1", "65432", 100)
    If @error Then
        Local $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not listen, Error code: " & $iError)
        Exit
    EndIf

            ;Browser to proxy
            Do
                $aSocket = TCPAccept($iLocalSocket)
                If @error Then
                    $iError = @error
                    MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not accept the incoming connection, Error code: " & $iError)
                    Exit
                EndIf
            Until $aSocket <> -1

            $Request = ""
            Do
                $iRequest = TCPRecv($aSocket, 1000, 0)
                $Request &=$iRequest
            Until @error <> -1
ConsoleWrite($Request)
            ;Some code here

            ;Proxy to browser
        $Response = "HTTP/1.1 200 OK" &@CRLF& _
                    "Server: nginx" &@CRLF& _
                    "Date: Sun, 27 Apr 2014 16:06:59 GMT" &@CRLF& _
                    "Content-Type: text/html" &@CRLF& _
                    "Content-Length: 77" &@CRLF& _
                    "Connection: keep-alive"&@CRLF&@CRLF& _
                    "<html><head><title>ABC</title></head><body>ABCDEF<b>ABCDEF</b></body></html>"
                    
                    
                
    TCPSend($aSocket, $Response)
TCPShutdown()

I'm learning about tcp / ip and have a question: when I put the proxy in IE is 127.0.0.1:65432 (local proxy) then redirect IE to address abc.com. How to IE display my html code?

Edited by DUNGYEUANH
Posted (edited)

Hi,

In your script you are sending some information when the browser connects to your proxy.

The thing is that you have to wait for a request before sending a response.

You will typically get :

GET http://abc.go.com/ HTTP/1.1
Host: abc.go.com
Proxy-Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
...

So you can detect the "GET" request type and then answer.

Br, FireFox.

Edited by FireFox
Posted (edited)

Thank Firefox.

That's exactly what I did but failed. To fix it just add "Connection: keep-alive" on $Response.

Edited by DUNGYEUANH

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
×
×
  • Create New...