Get Response from the Server Using POST Method

This code is use to get access or to get the response by passing request to the Server. for this we use the POST method. POST is the preferred method for sending lengthy form data. When a form is submitted POST the user does not see the form data that was sent


Public Sub GetResponse()
Dim Request As WebRequest = WebRequest.Create(url)
Request.Method = "POST"
Dim Instance As New WebException
Dim Value As WebExceptionStatus
'Set the ContentType property of the WebRequest.
Request.ContentType = "text"
'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()
End Sub


Thanks

Nilesh Jadhav


Comments

No responses found. Be the first to 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:
    Email: