Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / May 2008

Tip: Looking for answers? Try searching our database.

what's wrong with xml post code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CindyH - 11 May 2008 00:17 GMT
Hi
Trying to get this code to work for http xml post.
I need the post to be xml (doc.outerxml) sent in single key name as stream.
The following is the post code and code for receiving the request.
When it hits the "myresponse = myrequest.GetResponse()" in the post code -
I'm getting following error:
"The remote server returned an error: (500) Internal Server Error".
I don't know if I have something wrong with the post or receiving it on the
other end.
Right now I'm trying to write it in .net 1.1.
Any help will be greatly appreciated.
Thanks,
Cindy

       Dim url As String = "http://someplace.aspx"
       Dim myrequest As System.Net.WebRequest = Nothing
       Dim myresponse As System.Net.WebResponse = Nothing
       Try
           ' Create a request using a URL that can receive a post.
           myrequest = System.Net.WebRequest.Create(url)
           ' Set the Method property of the request to POST.
           myrequest.Method = "POST"
           ' Set the ContentType property of the WebRequest.
           myrequest.ContentType = "application/x-www-form-urlencoded"
           ' Create POST data and convert it to a byte array.
           Dim vxml = "Interface_2=" + HttpUtility.UrlEncode(Doc.OuterXml)
           Dim byteArray As Byte() =
System.Text.Encoding.UTF8.GetBytes(vxml)
           ' Set the ContentLength property of the WebRequest.
           myrequest.ContentLength = byteArray.Length
           ' Get the request stream.
           Dim dataStream As System.io.Stream =
myrequest.GetRequestStream()
           ' Write the data to the request stream.
           dataStream.Write(byteArray, 0, byteArray.Length)
           ' Close the Stream object.
           dataStream.Close()
           ' Get the response.
           myresponse = myrequest.GetResponse()     'error occurs here
       Catch ex As Exception
           Throw ex
       Finally
           ' Closed streams
           If Not myrequest Is Nothing Then
myrequest.GetRequestStream().Close()
           If Not myresponse Is Nothing Then
myresponse.GetResponseStream().Close()
       End Try

Code for receiving the post:
       Dim strReader As System.IO.StringReader = Nothing
       Dim Reader As System.Xml.XmlTextReader = Nothing
       Response.ContentType = "application/x-www-form-urlencoded"
       Response.Clear()
       Try
           strReader = New
System.IO.StringReader(Request.Form("Interface_2"))
           Reader = New System.Xml.XmlTextReader(strReader)
           Do While Reader.Read()
Bjoern Hoehrmann - 11 May 2008 14:49 GMT
* CindyH wrote in microsoft.public.dotnet.xml:
>Trying to get this code to work for http xml post.
>I need the post to be xml (doc.outerxml) sent in single key name as stream.
>The following is the post code and code for receiving the request.
>When it hits the "myresponse = myrequest.GetResponse()" in the post code -
>I'm getting following error:
>"The remote server returned an error: (500) Internal Server Error".

This means something has gone wrong on the server. It's quite possible
that this is a result of an error on your side, but without checking the
server (e.g., the logs, read source code of the remote application) it's
not possible to know for sure. You don't say, for example, whether this
works fine when using some other application to access the resource.
Signature

Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

Cindy H - 12 May 2008 11:55 GMT
I'm using xmlreader, not a xmltextreader and moved it to .net 2.0, but still
no luck.

> Hi
> Trying to get this code to work for http xml post.
[quoted text clipped - 56 lines]
>            Reader = New System.Xml.XmlTextReader(strReader)
>            Do While Reader.Read()

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.