Jump to content

problem with tcpsend()


Recommended Posts

well, im not sure exactly where the problem lies, but i made a simple script to send a get request to google, it sets @error when i try to use tcpsend, maybe someone can help me out, ive never had this problem before in autoit. ive been pretty proficient with using sockets in the past i even modded an http proxy written in autoit that i found to support all protocols. so, i've gotten my hands at least a bit dirty with autoit sockets, anyway past all that, here's my code:

TCPStartup()
httpget("google.com", "/")
Func httpget($host,$page)
   $gsock = TCPConnect(tcpnametoip($host),80)
   If @error Then
      TCPCloseSocket($gsock)
   Else
 Local $sCommand = "GET " & $page & " HTTP/1.1" & @CRLF
    
    $sCommand &= "Host: " & $host & @CRLF
    $sCommand &= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0" & @CRLF
    $sCommand &= "Referer: " & $host & @CRLF
    $sCommand &= "Connection: Keep-Alive" & @CRLF & @CRLF
    TCPSend($gsock,$sCommand)
    SetError(1)
    If @error = 1 Then
       MsgBox(0, "", "lol")
       TCPCloseSocket($gsock)
    Else
      MsgBox(0, "",_httprecv($gsock))
    EndIf
   EndIf
EndFunc
Func _httprecv($hsock)
   while 1
   $data = TCPRecv($hsock,600000)
   SetError(1)
   If @error = 1 Then
      TCPCloseSocket($hsock)
      ExitLoop
   Else
      Return StringReplace($data, ">", @crlf)
   EndIf
   WEnd
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...