I am using ASP.NET 4.5/VB.NET to POST a API response.
I get {"Illegal characters in path."} error in line 14.
.
My Json string after serialization is :
"{" & vbCrLf & " ""title"": ""testdata""," & vbCrLf & " ""body"": ""testbody""," & vbCrLf & " ""userid"": ""5""," & vbCrLf & " ""id"": ""50""" & vbCrLf & "}"
The above have some escape characters which I am not sure are the cause because.
I tried hard coding the above string to something like this (tried all single and all double quotes too):
Dim postData As String = "{\'title\':\'testdata\', \'body\':\'testbody\',\'userid\':\'testid\'}"
but this gives same error.
Public Sub ApiCall3()
Dim WebRequest As WebRequest =
WebRequest.Create("https://jsonplaceholder.typicode.com/posts")
WebRequest.Method = "POST"
WebRequest.ContentType = "application/json"
Dim dictData As New Dictionary(Of String, Object)
dictData.Add("title", "testdata")
dictData.Add("body", "testbody")
dictData.Add("userid", "5")
dictData.Add("id", "50")
Dim postData = JsonConvert.SerializeObject(dictData, Formatting.Indented)
Dim AWriter As StreamWriter = New StreamWriter(postData)
AWriter.Write(postData)
AWriter.Flush()
AWriter.Close()
Dim response As WebResponse = WebRequest.GetResponse()
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
Dim dataStream As Stream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd
Console.WriteLine(responseFromServer)
reader.Close()
response.Close()
End Sub
If someone could point me i the right direction I would be very grateful.