Thursday, 15 March 2012

amazon - Socket Error when using MWS SubmitFeed in Delphi using TIdHTTP -



amazon - Socket Error when using MWS SubmitFeed in Delphi using TIdHTTP -

i building application in delphi 2006 integrate amazon's mws api getting socket error 10061 connection refused.

here delphi code:

// pull out url end point - in case mws-eu.amazonservices.com:443 url := ''; url := getoption('url'); if url='' logmessage('dev','no amazon url in ini file! ', true); request := tstringlist.create; // add together standard required fields //request.add('marketplace='+getoption('marketplace')); request.add('action='+action); request.add('awsaccesskeyid='+getoption('awsaccesskeyid')); //request.add('mwsauthtoken='+getoption('mwsauthtoken')); //request.add('merchant='+getoption('sellerid')); request.add('sellerid='+getoption('sellerid')); request.add('signaturemethod='+getoption('signaturemethod')); // hmacsha256 request.add('signatureversion='+getoption('signatureversion')); // 2 request.add('version='+getoption('version')); // not sure comes or whether mutual calls ?? version=2009-01-01 // add together request specific params (these sent in function) loop := 0 params.count-1 begin request.add(paramsloop); end; // add together timestamp d:=now; dt:=formatdatetime('yyyy-mm-dd"t"hh:mm:ss"z"',d); request.add('timestamp='+dt); // phone call our custom sort method logmessage('dev','before='+request.gettext, false); request.customsort(stringlistcomparelogical); logmessage('dev','after='+request.gettext, false); // encode params per mws stringresult:=mwsencodeparams(request); logmessage('dev','result:'+stringresult, false); stringtosign := 'post' + char(10); stringtosign := stringtosign + url + char(10); stringtosign := stringtosign + '/' + char(10); stringtosign := stringtosign + stringresult; logmessage('dev','stringtosign:'+stringtosign, false); // phone call sha method in dll encrypter upugwash.getsh256_hmac(getoption('secretkey'),stringresult,true,signature); // add together result request signature request.add('signature='+signature); stringresult:=stringresult+'&signature='+signature; // phone call md5 method in dll encrypter upugwash.getmd5(requestbody,true,md5) ; logmessage('dev','output signature: '+signature, true); logmessage('dev','output md5: '+md5, true); lhttp := tidhttp.create(nil); liohandler:=tidssliohandlersocketopenssl.create(nil); liohandler.port := 443; // liohandler.port := 25; seek lhttp.iohandler := liohandler; lhttp.connecttimeout:=5000; lhttp.handleredirects := true; lhttp.readtimeout := 20000; lhttp.request.method := 'post'; lhttp.request.acceptcharset := 'utf-8'; lhttp.request.contenttype := 'text/xml'; //lhttp.request.contenttype:='application/x-www-form-urlencoded'; lhttp.request.contentencoding := 'utf-8'; lhttp.request.useragent := 'pos amazon web integration/'+getoption('posversion')+' (language=delphi/2006; customer='+getoption('customer')+')'; lhttp.request.host := url; lhttp.request.customheaders.add('x-amazon-user-agent: '+lhttp.request.useragent); lhttp.request.customheaders.add('content-md5: '+md5); lhttp.request.accept:='text/plain, */*'; lhttp.protocolversion:=pv1_1; lhttp.httpoptions:=lhttp.httpoptions+hokeeporigprotocol-hoforceencodeparams; rbody := tstringstream.create(requestbody); // feed xml rbody.seek(0,0); logmessage('dev','request body:'+requestbody, false); logmessage('dev','request url:'+stringresult, false); fullurl := 'https://'+url+'?'+stringresult; // url required parameters on end logmessage('dev','fullurl:'+fullurl, false); // create actual phone call rawresp := lhttp.post(fullurl,rbody); // falls on here socket exception

i have presumed above normal params sent in url , xml sent in body.

any pointers may going wrong much appreciated.

thank you!

i've been struggling indy , amazon web services lot too. particular error getting winsock error :

wsaeconnrefused 10061 connection refused.no connection made because target computer actively refused it. results trying connect service inactive on foreign host—that is, 1 no server application running.

acoording experience error may happen due several things:

wrong server adress or wrong port - check url , port service. create sure correct(i no expert in mws can't help that)

some firewall on client side blocking request - seek disable kinds of firewall , seek requesting again

a unstable net connection on client side can cause error

all in all, wouldn't encourage utilize indy i've seen fail in many situations. found out winhttp api altough little bit more complex way more stable.

hope of helps.

delphi amazon feed indy mws

No comments:

Post a Comment