delphi - How can I use Tidhttp to make a Get request with a parameter called xml? -
i've been using delphi 2010 make http requests, 1 service expects parameter called 'xml' request fails 'http/1.1 400 bad request' error.
i notice calling same service , omitting 'xml' parameter works.
i have tried following no success:
httpget('http://localhost/service/messaging.svc/sendreports/pdf?xml=<?xml version="1.0"?><email><message><to>email@internal.com</to><from>from@internal.com</from></message></email>&id=42&profile=a1');
...
function treportingframe.httpget(const url: string): string; var responsestream : tmemorystream; html: string; http: tidhttp; begin try try responsestream := tmemorystream.create; http := tidhttp.create(nil); http.onwork:= httpwork; http.request.contenttype := 'text/xml; charset=utf-8'; http.request.contentencoding := 'utf-8'; http.httpoptions := [hoforceencodeparams]; http.request.charset := 'utf-8'; http.get(url, responsestream); setstring(html, pansichar(responsestream.memory), responsestream.size); result := html; except on e: exception global.logerror(e, 'processhttprequest'); end; try http.disconnect; except end; end; end;
calling same url parameter name 'xml' renamed else, 'xml2' or 'name' same value above works. have tried multiple combinations of charset, think indy component changing internally.
edit
the service expects:
[webget(uritemplate = "sendreports/{format=pdf}?report={reportfile}¶ms={jsonparams}&xml={xmlfile}&profile={profile}&id={id}")]
has had experience this?
thanks
you need encode parameter data when passing via url, tidhttp
not encode url you, eg:
http.get(tiduri.urlencode('http://localhost/service/messaging.svc/sendreports/pdf?xml=<?xml version="1.0"?><email><message><to>email@internal.com</to><from>from@internal.com</from></message></email>&id=42&profile=a1'));
or:
http.get('http://localhost/service/messaging.svc/sendreports/pdf?xml=' + tiduri.paramsencode('<?xml version="1.0"?><email><message><to>email@internal.com</to><from>from@internal.com</from></message></email>') + '&id=42&profile=a1');
Comments
Post a Comment