• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

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

0
prowebinteractiveinc
Asked:
prowebinteractiveinc
  • 7
  • 7
5 Solutions
 
zc2Commented:
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?
0
 
prowebinteractiveincAuthor Commented:
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 ?
0
 
prowebinteractiveincAuthor Commented:
if I take out line 15 of my code everything works great...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
zc2Commented:
Do you mean the MAC address of the machine where the code is currently executed?
Try GetPhysicalAddress
like:
   For Each nic In NetworkInterface.GetAllNetworkInterfaces()
      nic.GetPhysicalAddress()    ' physical (MAC) address
   next nic

Open in new window


Dit you try to change the line 26 to the one I suggested?
0
 
zc2Commented:
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.
0
 
prowebinteractiveincAuthor Commented:
as per line 26, I did try changing it, the web server receiving the response doesnt reply anymore.

as for your GetPhysicalAddress... any imports ?
0
 
zc2Commented:
Imports System.Net.NetworkInformation
0
 
prowebinteractiveincAuthor Commented:
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 ?
0
 
zc2Commented:
To check the adapter status...
if nic.OperationalStatus = OperationalStatus.Up then 'get the address

Open in new window


Does that code execute on your application's client's PC? In other words, do you need to know just MAC address of the PC where the code is executed? Not some other network node?
0
 
prowebinteractiveincAuthor Commented:
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 ?
0
 
prowebinteractiveincAuthor Commented:
can I get system OS ?
0
 
zc2Commented:
Yes, it should be convertable to string
nic.GetPhysicalAddress().ToString()

Open in new window


To get the OS version, try this:
Imports System

str = Environment.OSVersion.VersionString   '  OS version string

Open in new window

0
 
prowebinteractiveincAuthor Commented:
the code Im using that you gave me is looping through 6x, first time is empty the rest give all the same physical address?
0
 
zc2Commented:
Well, you could try to filter out by the interface type which is the value of the NetworkInterfaceType property
if nic.NetworkInterfaceType = NetworkInterfaceType.Ethernet then ' use this adapter

Open in new window


BTW, if you execute in the command prompt this command: "ipconfig /all", will you see all 6 entries?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now