php simplexml_load_string($data) problem

Posted on 2012-09-18
Last Modified: 2012-09-22
I am sending the Mac Address of a logger to an application connected to my mySQL database.
it appears that the "%" in the mac address is considered an invalid char. I was wondering if there is a fix to this issue.

fe80::25ea:dfaa:bdd0:32f%11  (Suppose to be)
fe80::25ea:dfaa:bdd0:32f         (What is displayed while debugging)
Question by:prowebinteractiveinc
    LVL 83

    Expert Comment

    Where is VB.NET involved in that?
    LVL 107

    Expert Comment

    by:Ray Paseur
    I am not seeing a problem.
    <?php // RAY_temp_prowebinteractive.php
    $xml = <<<XML
    $obj = simpleXML_load_string($xml);

    Open in new window

    Perhaps you're looking at the browser-rendered HTML?  If so, you will see the entity created by %11.  I do not know what that might encode, but I expect it is down in the control characters and possibly invisible.

    Author Comment

    not looking at it in a browser, the only issue would have to be in the VB.NET when POSTING
    here is my code:

    Imports System
    Imports System.IO
    Imports System.Net
    Imports System.Text
    Public Class logVbUser
        Public Shared responseFromVbLogger As String
        Public Shared Sub Main(ByVal customerId As Integer, ByVal userId As Integer, ByVal pcName As String, ByVal macAddress As String)
            Dim xml As String
            xml = "logRequestMode=X&logRequestData="
            xml += "<?xml version='1.0' encoding='UTF-8'?>"
            xml += "<TranxRequest>"
            xml += "<CompanyId>" & customerId & "</CompanyId>"
            xml += "<UserId>" & userId & "</UserId>"
            xml += "<pcName>" & pcName & "</pcName>"
            xml += "<macAddress>" & macAddress & "</xxxName>"
            xml += "</TranxRequest>"
            'Form2.Label20.Text = xml
            ' Create a request using a URL that can receive a post. 
            Dim request As WebRequest = WebRequest.Create("http://" & databaseConnection.dbServer & "/includes/vbNetLogger.php")
            ' Set the Method property of the request to POST.
            request.Method = "POST"
            ' Create POST data and convert it to a byte array.
            Dim postData As String = xml
            Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
            ' Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded"
            ' Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length
            ' Get the request stream.
            Dim dataStream As Stream = request.GetRequestStream()
            ' Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length)
            ' Close the Stream object.
            ' Get the response.
            Dim response As WebResponse = request.GetResponse()
            ' Display the status.
            Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
            ' Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream()
            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            ' Display the content.
            responseFromVbLogger = responseFromServer
            ' Clean up the streams.
        End Sub
    End Class

    Open in new window

    LVL 107

    Accepted Solution

    Line 16 appears to be invalid XML:

    xml += "<macAddress>" & macAddress & "</xxxName>"

    Not sure if this is related to the issue, but it appears to be odd.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now