Jump to content
Sign in to follow this  

TCP receive and parse

Recommended Posts


Hi all,

I have this app I want to create, it goes online to my webserver and it receives an XML page containing orders.

I have it working, till the part where I get back the XML. The string that I receive also contains the headers and some stuff. :P

How do I filter out these headers, and I might as well ask emidiatly how do I pase the received XML?

This is what I receive, and the lines marked with ">>" are the ones I want removed by the script.

>>HTTP/1.1 200 OK

>>Date: Fri, 15 Aug 2008 15:54:10 GMT

>>Server: Apache/1.3.37 (Unix) mod_ssl/2.8.28 OpenSSL/0.9.7a PHP/4.4.6 mod_perl/1.29 FrontPage/

>>X-Powered-By: PHP/4.4.6

>>Connection: close

>>Transfer-Encoding: chunked

>>Content-Type: text/xml

>>X-Pad: avoid browser bug



<?xml version="1.0" encoding="ISO-8859-1"?>








But I have absolutly no idea how to do this.

I found this HTTP-Get functions on the forum, and it appeared to be working. But it also returns the headers:

Func _HTTPGet($sHost, $sPage)
    Local $iSocket = _HTTPConnect($sHost)
    If @error Then Return SetError(1, 0, "")
    Local $sCommand = "GET " & $sPage & " HTTP/1.1" & @CRLF
    $sCommand &= "Host: " & $sHost & @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: " & $sHost & @CRLF
    $sCommand &= "Connection: close" & @CRLF & @CRLF
    Local $BytesSent = TCPSend($iSocket, $sCommand)
    If $BytesSent = 0 Then Return SetError(2, @error, 0)
    Local $sRecv = "", $sCurrentRecv
    While 1
        $sCurrentRecv = TCPRecv($iSocket, 16)
        If @error <> 0 Then ExitLoop
        If $sCurrentRecv <> "" Then $sRecv &= $sCurrentRecv
    Return $sRecv

Func _HTTPConnect($sHost, $iPort=80)
    Local $sName_To_IP = TCPNameToIP($sHost)
    Local $iSocket = TCPConnect($sName_To_IP, $iPort)
    If $iSocket = -1 Then
        Return SetError(1, 0, "")
    Return $iSocket

Func _HTTPShutdown($iSocket)

Can someone please help me?

Thanks in advance!


[font="Verdana"]I've gone to find myself. If I get back before I return, please keep me here.[/font]

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.