Friday, 15 February 2013

json - Send POST HTTP request to google calendar/v3 API return parse error -



json - Send POST HTTP request to google calendar/v3 API return parse error -

i'm trying send http requests google calendar/v3 api using rest client library components in delphi xe5 update2(trestclient, trestrequest, trestoauth2autenticator, trestresponse). after settings components in delphi ide, requests working well, returning desired json response.

but post request (https://www.googleapis.com/calendar/v3/calendars/primary/events) parameter in trestrequest.params setting pkrequestbody alternative podonotencode , value of:

class="lang-json prettyprint-override">{ "end":{ "date":"2014-06-13" }, "start":{ "date":"2014-06-13" }, "summary":"retest" }

returns google api error:

class="lang-json prettyprint-override">{ "error":{ "errors":[ { "domain":"global", "reason":"parseerror", "message":"this api not back upwards parsing form-encoded input." } ], "code":400, "message":"this api not back upwards parsing form-encoded input." } }

this code , parameters working in delphi xe6 , not in xe5.

procedure tform2.button1click(sender: tobject); var rbody: tstringstream; begin rbody := tstringstream.create('{"end": {"date": "2014-06-13"},"start": {"date": "2014-06-13"},"summary": "retest"}'); restrequest.addbody(rbody, ctapplication_json); restrequest.execute; end;

is there someting i'm doing wrong , how can request working ? help.

you not setting restrequest correctly. likely, not setting request body's contenttype ctapplication_json. default, single-parameter restrequest utilize ctapplication_x_www_form_urlencoded unless specify otherwise. stated in documentation:

rest.client.trestrequestparameter.contenttype:

when parameter left empty, content type chosen depending on number of existing parameters, go requests body. a single-parameter request uses application/x-www-form-urlencoded, while multiple-parameter request uses multipart/mixed instead.

that explain why server complaining info beingness form-encoded. looking @ body's content-type header, sees unsupported value, , reports error ignoring actual body info sent.

json delphi http httprequest google-calendar

No comments:

Post a Comment