473,320 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

what's wrong with xml post code?

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()
Jun 27 '08 #1
2 2170
* 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.
--
Björn Höhrmann · mailto:bj****@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/
Jun 27 '08 #2
I'm using xmlreader, not a xmltextreader and moved it to .net 2.0, but still
no luck.

"CindyH" <ch*******@new.rr.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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()

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
5
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
5
by: Joey | last post by:
I am attempting to hook the onChange event for a dropdown list with javascript so that I can do some stuff and then initiate a postback with my code. I have not yet learned about how to do...
28
by: federico_bertola | last post by:
Hi everybody! I have this function: int Scan(char String) { printf("%s", String); } it works but when I try to pass a dotted string o separetad with (" ", "_" , "-" ...ecc)
11
pbmods
by: pbmods | last post by:
A somewhat obscure hack has emerged recently that is an offshoot of the now-infamous XSS. It is known as Cross-Site Request Forgery, or XSRF for short. XSRF is a form of temporary identity theft...
10
by: Enkidu | last post by:
Beginner question, sorry! I am using indexers to access an array of StringBuilders in an instance of a class: Getting: value = board1; Setting: board1 = value1 ;
2
by: CindyH | last post by:
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....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.