Reputation: 761
I'm trying to send a HTTP request to a servers interface. But I'm really confused about how to specify the parameters I want to send to the servers interface method. What I've done so far.
My server interface only accepts POST requests, that's why I'm using POST and asked if something is wrong with the way I use the parameters.
Dim parameters As String = "?text=test&type=person"
Dim buffer As Byte() = Encoding.UTF8.GetBytes(parameters)
Dim WebReq As HttpWebRequest = CType(WebRequest.Create(NameRecPage), HttpWebRequest)
'NameRecPage is the url
WebReq.Credentials = New NetworkCredential(Username, Password) 'variables are defined and theier values are valid
WebReq.Method = "POST"
WebReq.ContentType = "application/x-www-form-urlencoded"
WebReq.ContentLength = buffer.Length
Dim PostData As Stream = WebReq.GetRequestStream()
PostData.Write(buffer, 0, buffer.Length)
PostData.Close()
Dim WebResp As HttpWebResponse = DirectCast(WebReq.GetResponse(), HttpWebResponse)
Dim Answer As Stream = WebResp.GetResponseStream()
Dim _Answer As New StreamReader(Answer)
Dim inputBuffer As String = _Answer.ReadToEnd()
That's my code so far and it's sending a request. But i get an error saying that the first (and i think also the second) parameter is null.
I'm quite unsure about these two line:
Dim parameters As String = "?text=test&type=person"
WebReq.ContentType = "application/x-www-form-urlencoded"
Is there something wrong with my parameter syntax?
Are these spellings correct in my content? What is content type about? What does it say and how do I determine which value to put in there?
I don't know if thats the correct value for ContentType, actually I just want to receive some JSON fromatted data returned as string.
Upvotes: 0
Views: 1976
Reputation: 68
http://www.codeproject.com/Questions/158488/How-to-Post-Data-Using-WebRequest-with-Query-Strin
Upvotes: 1
Reputation: 8659
I think your problem in
WebReq.Method = "POST"
which should be GET
Upvotes: 0