Click here to Skip to main content
15,885,019 members
Please Sign up or sign in to vote.
4.67/5 (2 votes)
See more:
I'm facing problem in getting response for a POST method web request in vb.net and the GET request is working properly and getting the response, while the same request is working fine in C# with the same steps followed here. So, can any one help me to try to sort out this

Here Url is a Elastic search engine and the data in postData variable is a json string and the response will also be is a json string

Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("HOSTIP:9200/es5078_1/_search?pretty=true")

request.Method = "POST"
Dim postData As String = CGeneral.gstrMsgNC(236)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = postData.Length
request.Timeout = 100000

Dim writer As StreamWriter = New StreamWriter(request.GetRequestStream())
writer.Write(postData)
request.Expect = ""
request.AllowAutoRedirect = True
request.AllowWriteStreamBuffering = True

Dim response As System.Net.HttpWebResponse = request.GetResponse()

Dim responseReader As StreamReader = New StreamReader(response.GetResponseStream())
Dim result As String = responseReader.ReadToEnd()
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900