0

Attempting to do a WinHTTP request to submit form. One of the request body items is called 'StartDateTime' and when I view the request body in developer tools - I see it is sending " StartDateTime='03/04/2020 00:00:00' "

However, when I attempt to do this via VBA - I receive the the response: {"Data":null,"ModelState":{"Valid":false,"Message":"Error# 1 - Missing input parameter [ StartDateTime ]...

I have tried multiple attempts at reformatting the request body with no luck - including a direct copy/paste of the entire request body from developer tools

Dim XMLHttp As WinHttpRequest: Set XMLHttp = New WinHttpRequest
XMLHttp.Open "POST", URL, False
XMLHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
XMLHttp.send "StartDateTime='03/04/2020 00:00:00'"
Debug.Print XMLHttp.responseText
Set XMLHttp = Nothing

What am I doing wrong here?

  • Your content-type header has "urlencoded" so maybe look into how to urlencode values in VBA? Seems like you want something more like `StartDateTime%3D%2703%2F04%2F2020%2000%3A00%3A00%27` https://stackoverflow.com/questions/218181/how-can-i-url-encode-a-string-in-excel-vba – Tim Williams Mar 04 '20 at 18:46
  • @TimWilliams Thank you! This did not quite work (probably on me) but it did put me on the right path - using "application/json;charset=utf-8" as content type instead and matching the request body format I see did return results – colonel_mu5t4rd Mar 04 '20 at 19:08
  • OK - glad you figured it out – Tim Williams Mar 04 '20 at 19:10

0 Answers0