Subscribe to Subscribers

Online Members

Shine S
More...

Resources » Code Snippets » ASP.NET WebForms

Code to push Xml contents to URL by POST Method


Posted Date:     Category: ASP.NET WebForms    
Author: Member Level: Gold    Points: 7


This code is useful to push an any request to other URL using POST method



Code to push Xml contents to URL by POST Method


Description



This code is useful to push an any request to other URL using POST method
The below code is used to push an xml contents to URL and get the response.

First drag and drop one label with ID Lblresponse then on code behind write the below code,


you have to write xml node here
Dim PostData As String = "Write the xml tags here"

Dim Request As HttpWebRequest = DirectCast(WebRequest.Create("Write IP/URL to which push the xml here"), HttpWebRequest)
Dim ByteArray As Byte() = Encoding.UTF8.GetBytes(PostData)
Request.Method = "POST"
Dim Instance As New WebException
Dim Value As WebExceptionStatus
' Set the ContentType property of the WebRequest.
Request.ContentType = "text"
'Request.ContentType = "XML"
' Set the ContentLength property of the WebRequest.
Request.ContentLength = ByteArray.Length
' Get the Request stream.
Dim dataStream As Stream = Request.GetRequestStream()
' Write the data to the Request stream.

dataStream.Write(ByteArray, 0, ByteArray.Length)
' Close the Stream object.

dataStream.Close()
' Get the response.

Value = Instance.Status
Dim response As WebResponse = Request.GetResponse()
' Display the status.

Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
' Get the stream containing content returned by the server.

dataStream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.

Dim reader As New StreamReader(dataStream)
' Read the content.

Dim responseFromServer As String = reader.ReadToEnd()

Lblresponse.Text += responseFromServer
' Clean up the streams.

reader.Close()
dataStream.Close()
response.Close()





Did you like this resource? Share it with your friends and show your love!


Responses to "Code to push Xml contents to URL by POST Method"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to create Scrolbar with in Div?
    Previous Resource: How to bind Gridview with array datasource
    Return to Resources
    Post New Resource
    Category: ASP.NET WebForms


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Push xml to URL  .  Send request to any URL  .  

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2013 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.