我試圖發送HTTP請求來利用DELPHI XE5 UPDATE2的REST客戶端庫組件的谷歌日曆/ v3的API(TRESTClient
,TRESTRequest
,TRESToAuth2Autenticator
,TRESTResponse
) 。在Delphi IDE中設置這些組件後,GET請求運行良好,返回所需的JSON響應。發送POST HTTP請求發送到谷歌日曆/ V3 API返回解析錯誤
但是POST請求(https://www.googleapis.com/calendar/v3/calendars/primary/events)在TRESTRequest.params
參數與選項poDoNotEncode
和值設置爲pkREQUESTBODY
:
{
"end":{
"date":"2014-06-13"
},
"start":{
"date":"2014-06-13"
},
"summary":"reTest"
}
返回谷歌API錯誤:
{
"error":{
"errors":[
{
"domain":"global",
"reason":"parseError",
"message":"This API does not support parsing form-encoded input."
}
],
"code":400,
"message":"This API does not support parsing form-encoded input."
}
}
此代碼和參數在DELPHI XE6中運行良好,而不是在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;
是否有someting我做錯了,我該怎麼辦才能讓請求工作?謝謝你的幫助。
我已經tryed與僅一個TRESTRequest.params:contentType中設置爲ctAPPLICATION_JSON,一種設置爲pkREQUESTBODY和值設置爲{ 「結束」:{ 「日期」:「2014年6月13日」 }, 「開始」:{ 「日期」: 「2014年6月13日」 }, 「摘要」: 「複檢」 } 和我具有相同的錯誤響應,HTTP/1.0錯誤N°400, 此API不支持解析窗體編碼輸入 我不知道該怎麼辦 –
請顯示您的實際代碼。我使用REST協議失敗,但對'TRESTRequest'還不是很熟悉。這聽起來像你仍然沒有正確設置ContentType。它需要設置在請求的頂層。也許你正在設置它的身體級別,這可能會導致'TRESTRequest'發送'multipart/form-data'作爲請求的頂級ContentType。你能顯示正在傳輸的實際HTTP數據嗎? –
此代碼和參數在DELPHI XE6中運行良好,不在XE5中。我很失望,比價格這個工具! procedure TForm2.Button1Click(Sender:TObject); var rBody:TStringStream; rBody:= TStringStream.Create('{「end」:{「date」:「2014-06-13」},「start」:{「date」:「2014-06-13」},「summary 「:」reTest「}'); RESTRequest.AddBody(rBody,ctAPPLICATION_JSON); RESTRequest.Execute; 結束; –