VBA-tools / VBA-Web

VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web
http://vba-tools.github.io/VBA-Web/
MIT License
2.01k stars 494 forks source link

Display JSON message that will be sent out. #298

Closed kanhito1981 closed 7 years ago

kanhito1981 commented 7 years ago

Is there a way to display the JSON message that was generated before sending it out. Thanks, in advance. SS

nmhub commented 7 years ago

Have you tried WebHelpers.EnableLogging = True? It show's the JSON at the end of the --> Request section

timhall commented 7 years ago

The most straightforward way is to use the getter for Request.Body, which returns the converted string that is sent with the request.

Dim Body As New Dictionary
Body.Add "name", "Tim"

Dim Request As New WebRequest
Request.Format = WebFormat.Json
Set Request.Body = Body

Debug.Print Request.Body ' => {"name":"Tim"}

Request.Format = WebFormat.FormUrlEncoded
Debug.Print Request.Body ' => name=Tim

Additionally, I agree with @nmhub, when in doubt, try WebHelpers.EnableLogging = True somewhere in your code before the request. It logs requests and responses to the Immediate Window (VBA Editor + ctrl+g).