I want to POST json values via httpClient into an API. Unfortunately I am quite a beginner and can't handle it. GET works perfectly: here the code for GET:
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
' Wird für https-Requests benötigt
System.Net.ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)
request = DirectCast(WebRequest.Create(url), HttpWebRequest)
response = DirectCast(request.GetResponse(), HttpWebResponse)
reader = New StreamReader(response.GetResponseStream())
Dim s As String
s = reader.ReadToEnd
Return s
But how do I realize POST? My API-URL looks like this: https://mydomaine.net/api/auth?token=467445892587458542... an i will send an JSON-String {"test":"value1":"test1":"value2"} I've been working on this problem for many hours. Can someone please help ???
request.ContentType = "application/json", therequest.Method = WebRequestMethods.Http.Postand write to the Request Stream (request.GetRequestStream()) the JSON as UTF-8 bytes, probably. Does this API have any documentation related to posting data? -- Why are you casting SecurityProtocolType to theTls12Enum value? Are you still using a .Net Framework version prior to 4.5? Time to update.