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()

Re: what's wrong with xml post code? by Steve

Steve
Sat May 10 19:17:59 CDT 2008

CindyH wrote:

' request
> dataStream.Write(byteArray, 0, byteArray.Length)
> strReader = New

'server
> System.IO.StringReader(Request.Form("Interface_2"))
> Reader = New System.Xml.XmlTextReader(strReader)

It seems to me that you are writing a binary stream of bytes in the request, and
the server is attempting to read it with an XMTextReader.

I don't pretend to know all the ins and outs of streams, but I do know that text
streams and binary streams are two different animals. If you write binary, you
read binary; if you write text, you read text.

In your case, I would stick with text on both ends.Can't you just write a text
stream on the request end?



Re: what's wrong with xml post code? by Cor

Cor
Sun May 11 01:41:56 CDT 2008

Steve,

Good hit, however


> In your case, I would stick with text on both ends.Can't you just write a
> text stream on the request end?


What else binary over the Internet with Post, I never have seen that
working, but maybe I am wrong in this.
(As I see XML as well as text).


Cor


Re: what's wrong with xml post code? by Cindy

Cindy
Sun May 11 06:25:47 CDT 2008

I did have it as text on both ends and worked fine, but then I found out I
needed to send it as
as single key word:
"Interface_2=" + HttpUtility.UrlEncode(Doc.OuterXml)
I'm not sure how to post this or receive it on other end.



"CindyH" <chenschel@new.rr.com> wrote in message
news:ud9FqPvsIHA.4848@TK2MSFTNGP05.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()
>



Re: what's wrong with xml post code? by Steve

Steve
Sun May 11 10:28:08 CDT 2008

Cor Ligthert[MVP] wrote:
> Steve,
>
> Good hit, however
>
>> In your case, I would stick with text on both ends.Can't you just
>> write a text stream on the request end?
>
> What else binary over the Internet with Post, I never have seen that
> working, but maybe I am wrong in this.
> (As I see XML as well as text).
>

It is possible to send binary data as XML text. Usually it is Base64 encoded.
Base64 encoding is also how email attachments are sent around the Internet.



Re: what's wrong with xml post code? by Steve

Steve
Sun May 11 10:37:48 CDT 2008

Cindy H wrote:
> I did have it as text on both ends and worked fine, but then I found
> out I needed to send it as
> as single key word:
> "Interface_2=" + HttpUtility.UrlEncode(Doc.OuterXml)
> I'm not sure how to post this or receive it on other end.
>
>

Do you have to use streams? It sems to me that you could post it just as you
have it above, and on the receiving end, just retrieve it using
Request.Form("Interface_2"), assigning it directly to a string.



Re: what's wrong with xml post code? by Cor

Cor
Sun May 11 13:09:15 CDT 2008

Steve,

As it binary is in XML it is serialized.

Cor

"Steve Gerrard" <mynamehere@comcast.net> schreef in bericht
news:abadnYsz6f0VjbrVnZ2dnUVZ_tHinZ2d@comcast.com...
> Cor Ligthert[MVP] wrote:
>> Steve,
>>
>> Good hit, however
>>
>>> In your case, I would stick with text on both ends.Can't you just
>>> write a text stream on the request end?
>>
>> What else binary over the Internet with Post, I never have seen that
>> working, but maybe I am wrong in this.
>> (As I see XML as well as text).
>>
>
> It is possible to send binary data as XML text. Usually it is Base64
> encoded. Base64 encoding is also how email attachments are sent around the
> Internet.
>
>


Re: what's wrong with xml post code? by Cindy

Cindy
Mon May 12 05:56:05 CDT 2008

I'm using xmlreader, not a xmltextreader and moved it to .net 2.0, but still
no luck.




"CindyH" <chenschel@new.rr.com> wrote in message
news:ud9FqPvsIHA.4848@TK2MSFTNGP05.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()
>



Re: what's wrong with xml post code? by Cindy

Cindy
Mon May 12 05:57:37 CDT 2008

I'll try it - thanks.


"Steve Gerrard" <mynamehere@comcast.net> wrote in message
news:Sb6dnU_YZotRj7rVnZ2dnUVZ_tjinZ2d@comcast.com...
> Cindy H wrote:
>> I did have it as text on both ends and worked fine, but then I found
>> out I needed to send it as
>> as single key word:
>> "Interface_2=" + HttpUtility.UrlEncode(Doc.OuterXml)
>> I'm not sure how to post this or receive it on other end.
>>
>>
>
> Do you have to use streams? It sems to me that you could post it just as
> you have it above, and on the receiving end, just retrieve it using
> Request.Form("Interface_2"), assigning it directly to a string.
>
>



Re: what's wrong with xml post code? by CindyH

CindyH
Mon May 12 08:26:28 CDT 2008

I think he said it was going to be sent as a stream.


"Steve Gerrard" <mynamehere@comcast.net> wrote in message
news:Sb6dnU_YZotRj7rVnZ2dnUVZ_tjinZ2d@comcast.com...
> Cindy H wrote:
>> I did have it as text on both ends and worked fine, but then I found
>> out I needed to send it as
>> as single key word:
>> "Interface_2=" + HttpUtility.UrlEncode(Doc.OuterXml)
>> I'm not sure how to post this or receive it on other end.
>>
>>
>
> Do you have to use streams? It sems to me that you could post it just as
> you have it above, and on the receiving end, just retrieve it using
> Request.Form("Interface_2"), assigning it directly to a string.
>
>