473,385 Members | 1,908 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,385 software developers and data experts.

httputility.urlencode(doc.outerxml) as a http xml post

Hi
I'm not sure whether I should send this as a new message or use the one I've
been using but...
I'm using vb.net 2.0 -
My problem is I need to send
something like this: 'dim encodedstring = "test=" +
httputility.urlencode(doc.outerxml)' as a http xml post and then need to
receive it on other end for a test.
It needs to be sent as a stream.
I need some sample code on how to post it and then receive the request on
other end so I get the information from the xml.
Been playing around with all kinds of code and not getting anywhere.
Thanks,
Cindy
Jun 27 '08 #1
6 3861

Maybe you could explain the task a bit more ?

You want to send XML data with a post command , this you can not do without
encoding the XML data
this task is simple

But then you brought up streaming and i got confused , on HTTP everything is
text this doens`t mean you cannot send binary`s cause you can with encoding
and decoding ( BASE 64 or ROT 13 or even a custom protocol as long as the
outcome is a text format that doesn`t interfere with HTML tags )
hth

Michel

"CindyH" <ch*******@new.rr.comschreef in bericht
news:Oh**************@TK2MSFTNGP05.phx.gbl...
Hi
I'm not sure whether I should send this as a new message or use the one
I've been using but...
I'm using vb.net 2.0 -
My problem is I need to send
something like this: 'dim encodedstring = "test=" +
httputility.urlencode(doc.outerxml)' as a http xml post and then need to
receive it on other end for a test.
It needs to be sent as a stream.
I need some sample code on how to post it and then receive the request on
other end so I get the information from the xml.
Been playing around with all kinds of code and not getting anywhere.
Thanks,
Cindy

Jun 27 '08 #2
well the deal is that I need the post sent in key word - like
test=doc.outerxml

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:uA**************@TK2MSFTNGP03.phx.gbl...
>
Maybe you could explain the task a bit more ?

You want to send XML data with a post command , this you can not do
without encoding the XML data
this task is simple

But then you brought up streaming and i got confused , on HTTP everything
is text this doens`t mean you cannot send binary`s cause you can with
encoding and decoding ( BASE 64 or ROT 13 or even a custom protocol as
long as the outcome is a text format that doesn`t interfere with HTML
gs )
hth

Michel

"CindyH" <ch*******@new.rr.comschreef in bericht
news:Oh**************@TK2MSFTNGP05.phx.gbl...
>Hi
I'm not sure whether I should send this as a new message or use the one
I've been using but...
I'm using vb.net 2.0 -
My problem is I need to send
something like this: 'dim encodedstring = "test=" +
httputility.urlencode(doc.outerxml)' as a http xml post and then need to
receive it on other end for a test.
It needs to be sent as a stream.
I need some sample code on how to post it and then receive the request on
other end so I get the information from the xml.
Been playing around with all kinds of code and not getting anywhere.
Thanks,
Cindy


Jun 27 '08 #3
Okay

well i hope i understand this right ,,, but here is my implementation

Client code ( VB executable )

Imports System.Net
Imports System.Web
Imports System.Xml
Imports System
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim url As String = "http://localhost/Default.aspx"
Dim objDoc As New System.Xml.XmlDocument
objDoc.Load("c:\sample.xml")
MsgBox(SendAndReceive(url, objDoc.OuterXml))
End Sub

Public Function SendAndReceive(ByVal Url As String, ByVal vxml As
String) As String
Dim ResultHTML As String = String.Empty
Try
Dim myrequest As System.Net.WebRequest =
System.Net.WebRequest.Create(Url)
myrequest.Method = "POST"
myrequest.ContentType = "text/xml"

Dim byteArray As Byte() = System.Text.Encoding.UTF8.GetBytes(vxml)
myrequest.ContentLength = byteArray.Length
Dim dataStream As System.IO.Stream = myrequest.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()

Dim myresponse As System.Net.WebResponse = myrequest.GetResponse()
Dim Reader As New IO.StreamReader(myresponse.GetResponseStream)
ResultHTML = Reader.ReadToEnd()
Catch ex As Exception

End Try
Return ResultHTML
End Function

End Class
Server code ( default.aspx )

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Clear()
Dim Reader As New IO.StreamReader(Request.InputStream)
Dim result As String = Reader.ReadToEnd()
Response.Write(result)
End Sub

End Class

i hope above makes sence :-)

ofcourse in my example i just send the xml file and display the response of
the default.aspx just to see if the xml had arrived
but i guess this is what you wanted ??

HTH

Michel Posseth [MCP]


"CindyH" wrote:
well the deal is that I need the post sent in key word - like
test=doc.outerxml

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:uA**************@TK2MSFTNGP03.phx.gbl...

Maybe you could explain the task a bit more ?

You want to send XML data with a post command , this you can not do
without encoding the XML data
this task is simple

But then you brought up streaming and i got confused , on HTTP everything
is text this doens`t mean you cannot send binary`s cause you can with
encoding and decoding ( BASE 64 or ROT 13 or even a custom protocol as
long as the outcome is a text format that doesn`t interfere with HTML
gs )
hth

Michel

"CindyH" <ch*******@new.rr.comschreef in bericht
news:Oh**************@TK2MSFTNGP05.phx.gbl...
Hi
I'm not sure whether I should send this as a new message or use the one
I've been using but...
I'm using vb.net 2.0 -
My problem is I need to send
something like this: 'dim encodedstring = "test=" +
httputility.urlencode(doc.outerxml)' as a http xml post and then need to
receive it on other end for a test.
It needs to be sent as a stream.
I need some sample code on how to post it and then receive the request on
other end so I get the information from the xml.
Been playing around with all kinds of code and not getting anywhere.
Thanks,
Cindy


Jun 27 '08 #4
Yea, your code is almost exactly like how I orginally had mine when I was
first asked to do this, but then the client added this "key name" deal to
the project and said he wanted it sent as a single key name. I didn't know
what he was talking about then someone mentioned that he probably was
refering to this:
Dim encodedstring = "test=" + httputility.urlencode(doc.outerxml)'.
I asked him if this was correct and he said yes, so trying to come up with
the code to send and read the request on other end..
"Michel Posseth [MCP]" <Mi**************@discussions.microsoft.comwrote in
message news:2E**********************************@microsof t.com...
Okay

well i hope i understand this right ,,, but here is my implementation

Client code ( VB executable )

Imports System.Net
Imports System.Web
Imports System.Xml
Imports System
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim url As String = "http://localhost/Default.aspx"
Dim objDoc As New System.Xml.XmlDocument
objDoc.Load("c:\sample.xml")
MsgBox(SendAndReceive(url, objDoc.OuterXml))
End Sub

Public Function SendAndReceive(ByVal Url As String, ByVal vxml As
String) As String
Dim ResultHTML As String = String.Empty
Try
Dim myrequest As System.Net.WebRequest =
System.Net.WebRequest.Create(Url)
myrequest.Method = "POST"
myrequest.ContentType = "text/xml"

Dim byteArray As Byte() =
System.Text.Encoding.UTF8.GetBytes(vxml)
myrequest.ContentLength = byteArray.Length
Dim dataStream As System.IO.Stream =
myrequest.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()

Dim myresponse As System.Net.WebResponse =
myrequest.GetResponse()
Dim Reader As New IO.StreamReader(myresponse.GetResponseStream)
ResultHTML = Reader.ReadToEnd()
Catch ex As Exception

End Try
Return ResultHTML
End Function

End Class
Server code ( default.aspx )

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Clear()
Dim Reader As New IO.StreamReader(Request.InputStream)
Dim result As String = Reader.ReadToEnd()
Response.Write(result)
End Sub

End Class

i hope above makes sence :-)

ofcourse in my example i just send the xml file and display the response
of
the default.aspx just to see if the xml had arrived
but i guess this is what you wanted ??

HTH

Michel Posseth [MCP]


"CindyH" wrote:
>well the deal is that I need the post sent in key word - like
test=doc.outerxml

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:uA**************@TK2MSFTNGP03.phx.gbl...
>
Maybe you could explain the task a bit more ?

You want to send XML data with a post command , this you can not do
without encoding the XML data
this task is simple

But then you brought up streaming and i got confused , on HTTP
everything
is text this doens`t mean you cannot send binary`s cause you can with
encoding and decoding ( BASE 64 or ROT 13 or even a custom protocol
as
long as the outcome is a text format that doesn`t interfere with HTML
gs )
hth

Michel

"CindyH" <ch*******@new.rr.comschreef in bericht
news:Oh**************@TK2MSFTNGP05.phx.gbl...
Hi
I'm not sure whether I should send this as a new message or use the
one
I've been using but...
I'm using vb.net 2.0 -
My problem is I need to send
something like this: 'dim encodedstring = "test=" +
httputility.urlencode(doc.outerxml)' as a http xml post and then need
to
receive it on other end for a test.
It needs to be sent as a stream.
I need some sample code on how to post it and then receive the request
on
other end so I get the information from the xml.
Been playing around with all kinds of code and not getting anywhere.
Thanks,
Cindy



Jun 27 '08 #5
Cindy H schreef:
Yea, your code is almost exactly like how I orginally had mine when I was
first asked to do this, but then the client added this "key name" deal to
the project and said he wanted it sent as a single key name. I didn't know
what he was talking about then someone mentioned that he probably was
refering to this:
Dim encodedstring = "test=" + httputility.urlencode(doc.outerxml)'.
I asked him if this was correct and he said yes, so trying to come up with
the code to send and read the request on other end..
"Michel Posseth [MCP]" <Mi**************@discussions.microsoft.comwrote in
message news:2E**********************************@microsof t.com...
>Okay

well i hope i understand this right ,,, but here is my implementation

Client code ( VB executable )

Imports System.Net
Imports System.Web
Imports System.Xml
Imports System
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim url As String = "http://localhost/Default.aspx"
Dim objDoc As New System.Xml.XmlDocument
objDoc.Load("c:\sample.xml")
MsgBox(SendAndReceive(url, objDoc.OuterXml))
End Sub

Public Function SendAndReceive(ByVal Url As String, ByVal vxml As
String) As String
Dim ResultHTML As String = String.Empty
Try
Dim myrequest As System.Net.WebRequest =
System.Net.WebRequest.Create(Url)
myrequest.Method = "POST"
myrequest.ContentType = "text/xml"

Dim byteArray As Byte() =
System.Text.Encoding.UTF8.GetBytes(vxml)
myrequest.ContentLength = byteArray.Length
Dim dataStream As System.IO.Stream =
myrequest.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()

Dim myresponse As System.Net.WebResponse =
myrequest.GetResponse()
Dim Reader As New IO.StreamReader(myresponse.GetResponseStream)
ResultHTML = Reader.ReadToEnd()
Catch ex As Exception

End Try
Return ResultHTML
End Function

End Class
Server code ( default.aspx )

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Clear()
Dim Reader As New IO.StreamReader(Request.InputStream)
Dim result As String = Reader.ReadToEnd()
Response.Write(result)
End Sub

End Class

i hope above makes sence :-)

ofcourse in my example i just send the xml file and display the response
of
the default.aspx just to see if the xml had arrived
but i guess this is what you wanted ??

HTH

Michel Posseth [MCP]


"CindyH" wrote:
>>well the deal is that I need the post sent in key word - like
test=doc.outerxml

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:uA**************@TK2MSFTNGP03.phx.gbl...
Maybe you could explain the task a bit more ?

You want to send XML data with a post command , this you can not do
without encoding the XML data
this task is simple

But then you brought up streaming and i got confused , on HTTP
everything
is text this doens`t mean you cannot send binary`s cause you can with
encoding and decoding ( BASE 64 or ROT 13 or even a custom protocol
as
long as the outcome is a text format that doesn`t interfere with HTML
gs )
hth

Michel

"CindyH" <ch*******@new.rr.comschreef in bericht
news:Oh**************@TK2MSFTNGP05.phx.gbl...
Hi
I'm not sure whether I should send this as a new message or use the
one
I've been using but...
I'm using vb.net 2.0 -
My problem is I need to send
something like this: 'dim encodedstring = "test=" +
httputility.urlencode(doc.outerxml)' as a http xml post and then need
to
receive it on other end for a test.
It needs to be sent as a stream.
I need some sample code on how to post it and then receive the request
on
other end so I get the information from the xml.
Been playing around with all kinds of code and not getting anywhere.
Thanks,
Cindy
>

okay ....

the code i showed is the most common when sending XML over the wire

however you can also send it as an encoded string ,,,, as plain XML is
AFAIK impossible when using key value pairs

a simple solution would be

exe code

Imports System.Net
Imports System.Web
Imports System.Xml
Imports System
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim url As String = "http://localhost/Default.aspx"
Dim objDoc As New System.Xml.XmlDocument
objDoc.Load("c:\sample.xml")
MsgBox(SendAndReceive(url, objDoc.OuterXml))
End Sub

Public Function SendAndReceive(ByVal Url As String, ByVal vxml As
String) As String
Dim result As String = String.Empty
Try
Dim wc As New WebClient

Dim postdata As New Specialized.NameValueCollection

postdata.Add("Test", HttpUtility.UrlEncode(vxml))
wc.UploadValues(Url, "POST", postdata)
result =
System.Text.Encoding.UTF8.GetString(wc.UploadValue s(Url, "POST", postdata))
Catch ex As Exception

End Try
Return result
End Function
End Class
server code

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Clear()
Response.Write(HttpUtility.UrlDecode(Request.Form( "Test")))


End Sub

End Class
as you see you have now the problem that you need to decode the data on
the server side
hth

michel

Jun 27 '08 #6
Yep, that's right - I have to decode on other side.
Big pain - I just figured out how to do this, don't know if it's the best
way or not.
The guy tested it from his box and it seems to be working.
Thanks for all your input and taking the time to send me this code!

"Michel Posseth" <ms****@posseth.comwrote in message
news:u%****************@TK2MSFTNGP04.phx.gbl...
Cindy H schreef:
>Yea, your code is almost exactly like how I orginally had mine when I was
first asked to do this, but then the client added this "key name" deal to
the project and said he wanted it sent as a single key name. I didn't
know what he was talking about then someone mentioned that he probably
was refering to this:
Dim encodedstring = "test=" + httputility.urlencode(doc.outerxml)'.
I asked him if this was correct and he said yes, so trying to come up
with the code to send and read the request on other end..
"Michel Posseth [MCP]" <Mi**************@discussions.microsoft.comwrote
in message news:2E**********************************@microsof t.com...
>>Okay

well i hope i understand this right ,,, but here is my implementation

Client code ( VB executable )

Imports System.Net
Imports System.Web
Imports System.Xml
Imports System
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim url As String = "http://localhost/Default.aspx"
Dim objDoc As New System.Xml.XmlDocument
objDoc.Load("c:\sample.xml")
MsgBox(SendAndReceive(url, objDoc.OuterXml))
End Sub

Public Function SendAndReceive(ByVal Url As String, ByVal vxml As
String) As String
Dim ResultHTML As String = String.Empty
Try
Dim myrequest As System.Net.WebRequest =
System.Net.WebRequest.Create(Url)
myrequest.Method = "POST"
myrequest.ContentType = "text/xml"

Dim byteArray As Byte() =
System.Text.Encoding.UTF8.GetBytes(vxml)
myrequest.ContentLength = byteArray.Length
Dim dataStream As System.IO.Stream =
myrequest.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()

Dim myresponse As System.Net.WebResponse =
myrequest.GetResponse()
Dim Reader As New
IO.StreamReader(myresponse.GetResponseStream)
ResultHTML = Reader.ReadToEnd()
Catch ex As Exception

End Try
Return ResultHTML
End Function

End Class
Server code ( default.aspx )

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Clear()
Dim Reader As New IO.StreamReader(Request.InputStream)
Dim result As String = Reader.ReadToEnd()
Response.Write(result)
End Sub

End Class

i hope above makes sence :-)

ofcourse in my example i just send the xml file and display the response
of
the default.aspx just to see if the xml had arrived
but i guess this is what you wanted ??

HTH

Michel Posseth [MCP]


"CindyH" wrote:

well the deal is that I need the post sent in key word - like
test=doc.outerxml

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:uA**************@TK2MSFTNGP03.phx.gbl...
Maybe you could explain the task a bit more ?
>
You want to send XML data with a post command , this you can not do
without encoding the XML data
this task is simple
>
But then you brought up streaming and i got confused , on HTTP
everything
is text this doens`t mean you cannot send binary`s cause you can with
encoding and decoding ( BASE 64 or ROT 13 or even a custom protocol
as
long as the outcome is a text format that doesn`t interfere with HTML
gs )
>
>
hth
>
Michel
>
"CindyH" <ch*******@new.rr.comschreef in bericht
news:Oh**************@TK2MSFTNGP05.phx.gbl.. .
>Hi
>I'm not sure whether I should send this as a new message or use the
>one
>I've been using but...
>I'm using vb.net 2.0 -
>My problem is I need to send
>something like this: 'dim encodedstring = "test=" +
>httputility.urlencode(doc.outerxml)' as a http xml post and then need
>to
>receive it on other end for a test.
>It needs to be sent as a stream.
>I need some sample code on how to post it and then receive the
>request on
>other end so I get the information from the xml.
>Been playing around with all kinds of code and not getting anywhere.
>Thanks,
>Cindy
>>
>


okay ....

the code i showed is the most common when sending XML over the wire

however you can also send it as an encoded string ,,,, as plain XML is
AFAIK impossible when using key value pairs

a simple solution would be

exe code

Imports System.Net
Imports System.Web
Imports System.Xml
Imports System
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim url As String = "http://localhost/Default.aspx"
Dim objDoc As New System.Xml.XmlDocument
objDoc.Load("c:\sample.xml")
MsgBox(SendAndReceive(url, objDoc.OuterXml))
End Sub

Public Function SendAndReceive(ByVal Url As String, ByVal vxml As
String) As String
Dim result As String = String.Empty
Try
Dim wc As New WebClient

Dim postdata As New Specialized.NameValueCollection

postdata.Add("Test", HttpUtility.UrlEncode(vxml))
wc.UploadValues(Url, "POST", postdata)
result =
System.Text.Encoding.UTF8.GetString(wc.UploadValue s(Url, "POST",
postdata))
Catch ex As Exception

End Try
Return result
End Function
End Class
server code

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Response.Clear()
Response.Write(HttpUtility.UrlDecode(Request.Form( "Test")))


End Sub

End Class
as you see you have now the problem that you need to decode the data on
the server side
hth

michel

Jun 27 '08 #7

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

Similar topics

1
by: Colin Crossman | last post by:
So, I'm trying to write a web spider for some data gathering from a public database webserver. Anyway, in response to a POST, the webserver returns "200 Script Results Follow" instead of "201...
4
by: James Johnson | last post by:
Dear C#Dex, I am trying to automate a POST to a web page that clicks a button. I have been able to hit a target web page and run the web page. However, the button on the page does not click. ...
4
by: Andreas Klemt | last post by:
Hello, is there a difference between System.Web.HttpUtility.UrlEncode and Server.UrlEncode ?
0
by: Anthony | last post by:
Hi all, I am just trying to set up a form post to worldppay and finding it surprisingly difficult.. What i would like is to gather all of the variables needed in c# codebehind and then send them...
0
by: Owen | last post by:
Hello everyone, I am using VS.NET 2003(Trandition Chinese) Edition, and httpLook software for checking http requests. I found a problem that the following programs don't really "POST". These...
0
by: CindyH | last post by:
Hi I'm not sure whether I should send this as a new message or use the one I've been using but... I'm using vb.net 2.0 - My problem is I need to send something like this: 'dim encodedstring =...
1
by: CindyH | last post by:
Hi I'm not sure whether I should send this as a new message or use the one I've been using but... I'm using vb.net 2.0 - My problem is I need to send something like this: 'dim encodedstring =...
0
by: CindyH | last post by:
Hi I'm using .net 2.0. I am receiving a http post that is sent httpUtility.urlencode(doc.Outerxml). Everything works fine and I can receive the post and parse it, but I need to set...
2
by: CindyH | last post by:
Hi I'm using .net 2.0. I am receiving a http post that is sent httpUtility.urlencode(doc.Outerxml). Everything works fine and I can receive the post and parse it, but I need to set...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.