Link to home
Start Free TrialLog in
Avatar of prowebinteractiveinc
prowebinteractiveinc

asked on

error Posting XML with characters in a Mac Address

I am posting an XML string to a server that logs users connecting to my mySQL database.
one of the variables is a Mac Addresseg: fe80::25ea:dfaa:bdd0:32f%11.

Im guessing the issue is the non alphanumeric characters as non utf-8 ?  but im not sure
here is the code Im using maybe someone can help me figure out why my program is crashing because of the IP address.

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>"

        ' 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.
        dataStream.Close()
        ' 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
        Console.WriteLine(responseFromServer)
        ' Clean up the streams.
        reader.Close()
        dataStream.Close()
        response.Close()
    End Sub
End Class

Open in new window

Avatar of zc2
zc2
Flag of United States of America image

It's not a MAC address, it's an IPv6 address...

You should pass a correct ContentType value, like
request.ContentType = "text/xml; charset=UTF-8"

Open in new window


Do you know where exactly your program is crashed, at what line? Is there any exception, error code or something?
Avatar of prowebinteractiveinc
prowebinteractiveinc

ASKER

the .NET program is not crashing its the web server that is trying to read and parse the XML string because of invalid characters. is there a way to get the Mac address instead of the IPv6
I want to be able to pin point the computer used to login to the system. any suggestions ?
if I take out line 15 of my code everything works great...
ASKER CERTIFIED SOLUTION
Avatar of zc2
zc2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My guess - the "%11" in the line 15 is unescaped on the server to the ASCII control code DC1, which could affect the server somehow...
Because the server treat your message as URL form encoded, not as an XML.
You need to tell to the server the correct content type, so it will know what it exactly is in the HTTP body.
as per line 26, I did try changing it, the web server receiving the response doesnt reply anymore.

as for your GetPhysicalAddress... any imports ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
zc2

ok I have 2 network adapters on my computer, is there a way to display only the one that is being used to connect ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the code does execute on the clients PC.. I am trying to gather the most information about the users PC for security purposes...

last question,  what type is nic.GetPhysicalAddress()
can it be converted as a String ?
can I get system OS ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the code Im using that you gave me is looping through 6x, first time is empty the rest give all the same physical address?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial