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 / ASP.NET / Web Services / February 2005

Tip: Looking for answers? Try searching our database.

HTTP POST ASP .NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Timothy Bales - 21 Jan 2005 09:37 GMT
Could someone PLEASE explain how do I use HTTP POST in ASP .NET to get an
xml string from a server that exposes a web service? My IIS server will
receive a username and password from an HTML form and will have to send that
info via HTTP POST to another server that exposes the web service, I then
will have to parse the XML output received from the remote web service,
format it and send to the user on a web page. My IIS server is in the
middle, I need to pass the user info to the remote web service and then the
XML output back from the remote web service to the end user's browser.

Just a snippet of code for the background HTTP POST in ASP .NET, I have
checked a lot of ASP .NET books and none of them touches on this scenario.

THANKS,

Tim.
Martin Kulov - 22 Jan 2005 15:56 GMT
Hi Timothy,

use HttpRequest class to format a POST request. It is pretty trivial.

Best,

Signature

Martin Kulov
http://www.codeattest.com

MCAD Charter Member
MCSD.NET Early Achiever
MCSD

> Could someone PLEASE explain how do I use HTTP POST in ASP .NET to get an
> xml string from a server that exposes a web service? My IIS server will
[quoted text clipped - 11 lines]
>
> Tim.
Ken Cox [Microsoft MVP] - 22 Jan 2005 17:37 GMT
Hi Tim,

I like using WebClient for that. You need to include the name of the
parameter that the target page expects.

Here's some sample code that might get you started. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

(See also
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemnetwebclientclasstopic.asp
)

   Sub DoPost()
       Dim uriString As String = _
       "http://localhost/p4320work/mySpecialPage.aspx"
       Dim strGoName As String
       strGoName = TextBox1.Text
       ' Create a new WebClient instance.
       Dim myWebClient As New System.Net.WebClient
       Dim myNameValueCollection As New _
         System.Collections.Specialized.NameValueCollection
       myNameValueCollection.Add("go1", strGoName)
       myNameValueCollection.Add("Button1", "")
       Dim responseArray As Byte() = myWebClient.UploadValues _
       (uriString, "POST", myNameValueCollection)
   '    Response.Redirect("http://msdn.microsoft.com/")
   End Sub

   Private Sub Button1_Click _
   (ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles Button1.Click
       Call DoPost()
   End Sub

 <form id="Form1" method="post" runat="server">
  <P>
   <asp:TextBox id="TextBox1" runat="server">test</asp:TextBox></P>
  <P>
   <asp:Label id="Label1" runat="server">Label</asp:Label></P>
  <P>
   <asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
 </form>

> Could someone PLEASE explain how do I use HTTP POST in ASP .NET to get an
> xml string from a server that exposes a web service? My IIS server will
[quoted text clipped - 13 lines]
>
> Tim.
Ken Cox [Microsoft MVP] - 22 Jan 2005 17:38 GMT
Hmmm... you might want this version instead if you need to see the
response...

  Sub DoPost()
       Dim uriString As String = _
       "http://p4320/p4320work/login.aspx"
       ' Create a new WebClient instance.
       Dim myWebClient As New System.Net.WebClient
       Dim myNameValueCollection As New _
         System.Collections.Specialized.NameValueCollection
       myNameValueCollection.Add("txtName", "Ken")
       myNameValueCollection.Add("txtPwd", "password")
       myNameValueCollection.Add("Button1", "")
       Dim responseArray As Byte() = myWebClient.UploadValues _
       (uriString, "POST", myNameValueCollection)
       Label1.Text = "Response received was :" & _
       System.Text.Encoding.ASCII.GetString(responseArray)
   End Sub

> Could someone PLEASE explain how do I use HTTP POST in ASP .NET to get an
> xml string from a server that exposes a web service? My IIS server will
[quoted text clipped - 13 lines]
>
> Tim.
Timothy Bales - 24 Jan 2005 21:22 GMT
Guys I really appreciate your help. I'm using WebClient and have finally
been able to do what I wanted to do. What has me puzzled right now is that I
was not expecting formatted XML output but at least the description of the
fields and I'm only getting their values. When I convert from Byte to String
I get a long string with all the values concatenated. Is this right? When I
query the server from the browser address bar using the same parameters that
I send programmatically I get a complete XML document with the field names
and everything not only the values.

Again, thanks a lot.

Tim.

> Hmmm... you might want this version instead if you need to see the
> response...
[quoted text clipped - 33 lines]
>>
>> Tim.
obinna - 10 Feb 2005 03:56 GMT
Could you send me code on how to send & retrieve http post pls

> *Could someone PLEASE explain how do I use HTTP POST in ASP .NET t
> get an
[quoted text clipped - 21 lines]
>
> Tim.



Rate this thread:







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.