Request to Amazon API with delphi : Got HTTP/1.1 403 Forbidden -



Request to Amazon API with delphi : Got HTTP/1.1 403 Forbidden -

i not know code right or wrong. when seek run programme error occurs 403..

unit unit1; interface uses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs,ssbase64, stdctrls,secutils,omnixmlutils,omnixml, xmldom, xmlintf, msxmldom, xmldoc, idbasecomponent, idcomponent, idtcpconnection, idtcpclient, idhttp,iduri; type tform1 = class(tform) button1: tbutton; memo1: tmemo; xmldocument1: txmldocument; idhttp1: tidhttp; memo2: tmemo; memo3: tmemo; procedure button1click(sender: tobject); private { private declarations } public { public declarations } end; var form1: tform1; implementation {$r *.dfm} function myencodeurl(source:string):string; var i:integer; begin result := ''; := 1 length(source) if not (source[i] in ['a'..'z','a'..'z','0','1'..'9','-','_','~','.']) result := result + '%'+inttohex(ord(source[i]),2) else result := result + source[i]; end; procedure tform1.button1click(sender: tobject); var uhost,uri,public_key, private_key,signature,timestamp,string_to_sign : string; request : string; begin uhost := 'ecs.amazonaws.com'; uri := 'onca/xml'; public_key := '1etptjhq37p671hnxxx'; private_key := 'j4jtmhqwl6wr39fy2cjgnfhibljk9gsc5z6xxxx'; timestamp := myencodeurl(xmldatetimetostr(now)); string_to_sign := 'awsaccesskeyid=1etptjhq37p671hn9282'; string_to_sign := string_to_sign+ '&associatetag=moc-20&itempage=1&keywords=kitchen%20aid&operation=itemsearch&responsegroup=large&searchindex=kitchen&'; string_to_sign := string_to_sign+'service=awsecommerceservice&timestamp='+timestamp; string_to_sign := string_to_sign+'&version=2009-03-31'; memo1.clear; memo1.lines.append('get'); memo1.lines.append('ecs.amazonaws.com'); memo1.lines.append('/onca/xml'); memo1.lines.append(string_to_sign); signature := strtomime64(hmacstring(hasha256, private_key, 32, memo1.text)); request := 'http://ecs.amazonaws.com/onca/xml?awsaccesskeyid=1etptjhq37p671hn9282'; request := request+ '&associatetag=moc-20&itempage=1&keywords=kitchen%20aid&operation=itemsearch&responsegroup=large&searchindex=kitchen&'; request := request+'service=awsecommerceservice&timestamp='+timestamp; request := request+'&version=2009-03-31'; request := request+'&signature='+signature; memo1.text := idhttp1.get(request); end; end.

can body trace error??

fyi :: delphi 7 build in indy; utilize omnixml generate timestamp utilize openstrsecii generate signature

amazon sends xml document exactly describes why got 403 error. easiest way see message utilize fiddler , set indy http utilize 127.0.0.1 proxy. way traffic goes through fiddler , you'll see both sent , amazon returned.

when implemented rest api work amazon s3 service had problems figuring out "canonical headers" need signed. happily amazon api sends text they're signing test signature, can compare byte-by-byte , figure out if you're doing wrong. failure prepare "canonical headers" they're preparing headers result in 403. illustration line separator amazon using linefeed (#10). since you're putting headers in tmemo, you're going windows-style crlf separator. lone plenty code fail.

an other thing had problems sending headers indy requests. next on-line api samples, looking @ i'm supposed send , amazon supposed answer. fiddler way test , see i'm sending, opposed thought sending. illustration mistakenly used tidhttp.request.rawheaders write custom headers, headers flushed while request prepared. supposed write headers tidhttp.request.customheaders - without fiddler's help wouldn't know i'm not sending headers. code looked fine.

delphi api rest amazon-web-services amazon

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -