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%1 1.
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.
one of the variables is a Mac Addresseg: fe80::25ea:dfaa:bdd0:32f%1
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
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 ?
I want to be able to pin point the computer used to login to the system. any suggestions ?
ASKER
if I take out line 15 of my code everything works great...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
as per line 26, I did try changing it, the web server receiving the response doesnt reply anymore.
as for your GetPhysicalAddress... any imports ?
as for your GetPhysicalAddress... any imports ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 ?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 ?
last question, what type is nic.GetPhysicalAddress()
can it be converted as a String ?
ASKER
can I get system OS ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You should pass a correct ContentType value, like
Open in new window
Do you know where exactly your program is crashed, at what line? Is there any exception, error code or something?