I need to post a json for a webservice (https://www.statcan.gc.ca/eng/developers/wds/user-guide#a12-5). This is public and you can navigate to this page/web service
I try to use "getBulkVectorDataByRange" method from this page. ex
POST URL:
https://www150.statcan.gc.ca/t1/wds/rest/getBulkVectorDataByRange
POST BODY:
{
"vectorIds": ["74804"],
"startDataPointReleaseDate": "2015-12-01T08:30",
"endDataPointReleaseDate": "2018-03-31T19:00"
}
I use
Public Sub Main()
Dim JsonData As String = "{""vectorIds"" : [""74804""], ""startDataPointReleaseDate"" : ""2015-12-01T0830"", ""endDataPointReleaseDate"" : ""2018-03-31T19:00""}"
Dim myRequest As HttpWebRequest = PostJSON(JsonData)
Console.WriteLine("Response of Request:{0}", GetResponse(myRequest))
Console.ReadKey()
End Sub
Private Function PostJSON(ByVal JsonData As String) As HttpWebRequest
Dim objhttpWebRequest As HttpWebRequest
Try
Dim httpWebRequest = DirectCast(WebRequest.Create("https://www150.statcan.gc.ca/t1/wds/rest/getBulkVectorDataByRange"), HttpWebRequest)
httpWebRequest.Method = "POST"
httpWebRequest.ContentType = "application/json"
httpWebRequest.MediaType = "application/json"
httpWebRequest.Accept = "application/json"
Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream(), Encoding.UTF8)
streamWriter.Write(JsonData)
streamWriter.Flush()
streamWriter.Close()
End Using
objhttpWebRequest = httpWebRequest
Catch ex As Exception
Console.WriteLine("Send Request Error[{0}]", ex.Message)
Return Nothing
End Try
Return objhttpWebRequest
End Function
Private Function GetResponse(ByVal httpWebRequest As HttpWebRequest) As String
Dim strResponse As String = "Bad Request:400"
Try
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
Dim StreamReader As StreamReader = New StreamReader(DirectCast(httpResponse.GetResponseStream(), String), True)
Dim result = StreamReader.ReadToEnd()
strResponse = result.ToString()
Catch ex As Exception
Console.WriteLine("GetResponse Error[{0}]", ex.Message)
Return ex.Message
End Try
Return strResponse
End Function
At the bolded line I get "The remote server returned an error: (406) Not Acceptable."
Can you please assist with methods for POST a json file (and return Json) as I indicated on the public web service in this post.
I looked on internet but no post helped.
Thank you,