Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

XML Data


Best Answer seascan, 19 January 2014 - 06:45 PM

Solved!

 

I added a header:

Send(client, "HTTP/1.0 200 OK" & vbCr & vbLf & "Content-Type: text/xml; charset=utf-8" & vbCr & vbLf & "Content-Length: " & Mystring.Length.ToString() & vbCr & vbLf & vbCr & vbLf)
Go to the full post


  • Please log in to reply
1 reply to this topic

#1 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 19 January 2014 - 03:18 PM

Are there any .Net experts in the audience?

 

I have a webserver running on a ND+1.  It works great.  I'm sending back a small bit of XML for testing.  When I load up the webpage in IE or chrome it looks perfect.  However, when I try to read this XML from a ASP.Net page I get "Additional information: The underlying connection was closed: The connection was closed unexpectedly."

 

Here's my huge ASP.Net webpage (i trimmed everything down to just the line throwing the error):

Imports System.XmlImports System.Net.SocketsPublic Class GetData    Inherits System.Web.UI.Page    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        Dim xmlDoc = XDocument.Load(MyIpAddress)    End SubEnd Class

Here's my code for returning the XML:

 Private Sub Send(client As Socket, response As String)        client.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None)    End Sub    Private Sub SendXML(client As Socket)        Dim Mystring As String = ""        Mystring = "<?xml version=" & Convert.ToChar(34) & "1.0" & Convert.ToChar(34) & " encoding=" & Convert.ToChar(34) & "UTF-8" & Convert.ToChar(34) & "?>"        Mystring += "<DataTable>"        Mystring += "<Data>"        Mystring += "<Temp1_C>28.0</Temp1_C>"        Mystring += "</Data>"        Mystring += "</DataTable>"        Send(client, Mystring)End Sub

I have added this to my asp.net web.config:

  <system.net>    <settings>      <httpWebRequest useUnsafeHeaderParsing="true" />    </settings>  </system.net>

Any thoughts?  Thanks!



#2 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 19 January 2014 - 06:45 PM   Best Answer

Solved!

 

I added a header:

Send(client, "HTTP/1.0 200 OK" & vbCr & vbLf & "Content-Type: text/xml; charset=utf-8" & vbCr & vbLf & "Content-Length: " & Mystring.Length.ToString() & vbCr & vbLf & vbCr & vbLf)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.