Sign in to follow this  
Followers 0
RobertK

TCP receive and parse

1 post in this topic

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/5.0.2.2510

>>X-Powered-By: PHP/4.4.6

>>Connection: close

>>Transfer-Encoding: chunked

>>Content-Type: text/xml

>>X-Pad: avoid browser bug

>>

>>65

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

<tree>

<child>

<name>HOI</name>

</child>

</tree>

>>

>>0

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
    WEnd
   
    _HTTPShutdown($iSocket)
   
    Return $sRecv
EndFunc

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

Func _HTTPShutdown($iSocket)
    TCPCloseSocket($iSocket)
    TCPShutdown()
EndFunc

Can someone please help me?

Thanks in advance!

Robert


[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  
Followers 0