Title: Simple 3rd party WebService with GET or POST Post by: ISIGest on October 04, 2013, 03:18:33 PM Hi, I need to to access to a simple webservice that accept this params:
http://webservice.mysite.com/?token=Token&action=info&cardCode=mycode with indy component is very simple to call encoding the url and with Get method that return the result. this is my code: Code: with DataMain.HTTPDataRequest.Request, Params do How I can call and get the result with RTC HTTP Client? Title: Re: Simple 3rd party WebService with GET or POST Post by: D.Tkalcec (RTC) on October 04, 2013, 03:30:36 PM In the RTC SDK, you cau either set the complete URI by using the Request.URI property like this ...
HttpDateRequest.Request.URI:='/?token=Token&action=info&cardCode=mycode'; Or you can set each individual query parameter by using the Request.Query[] property, like this ... HttpDataRequest.Request.Query['token']:='Token'; HttpDataRequest.Request.Query['action']:='info'; HttpDataRequest.Request.Query['cardCode']:='myCode'; Best Regards, Danijel Tkalcec Title: Re: Simple 3rd party WebService with GET or POST Post by: ISIGest on October 04, 2013, 03:34:26 PM Ok, but after ".Post()" method, nothing happens...
Title: Re: Simple 3rd party WebService with GET or POST Post by: D.Tkalcec (RTC) on October 04, 2013, 03:37:49 PM Check this QuickStart lesson. (http://www.realthinclient.com/sdkarchive/indexd703d703.html)
It explains the basics of using RtcHttpClient and RtcDataRequest components to send requests to WebServers and receive a result. The only "missing piece" is the informatioon I've provided above. Best Regards, Danijel Tkalcec Title: Re: Simple 3rd party WebService with GET or POST Post by: ISIGest on October 04, 2013, 04:15:03 PM Ok solved, my error is missing WriteHeader in OnBeginRequest event....
it would be nice to have a method "PostAndWriteHeader()" that also send the header without listening for the event "OnBeginRequest". This webservice reply a result like this: "action=info&status=0&result=ok" there is an object or method to manage this result, like a TRtcValue o TRTCRecord, to have something similar to: myRecord.AsString['action'] or myRecord.AsString['result']?? Title: Re: Simple 3rd party WebService with GET or POST Post by: D.Tkalcec (RTC) on October 04, 2013, 04:31:33 PM 1) Even if you didn't have to implement the OnBeginRequest event (because you only wanted to call "WriteHeader" there), you would still need to implement the OnDataReceived event to handle the response.
2) Normally, you would use the Read or ReadEx method to get the content body sent from the Server and parse it as you see fit. For JSON responses, you can also use the TRtcValue object. There is no built-in way for automatically parsing URL-Encoded response content received from 3rd-party Severs. However, if you are NOT already using the "Request.Params" object for preparing parameters for the Request, you could assign the response content to the Request.Params object (see the "AddText" method) as it arrives, wait for Response.Done and then access each parameter through Request.Params['item-name']. It's a bit of a "hack", because this property is actually meant to be used for Request parameters, but it should do the trick. Best Regards, Danijel Tkalcec Title: Re: Simple 3rd party WebService with GET or POST Post by: D.Tkalcec (RTC) on February 16, 2017, 08:55:07 AM Well ... it took me 3.5 years to realize that the requirement to always implement the OnBeginRequest event on the TRtcDataRequest component did not make much sense if all you have to do there is call "Write" or "WriteHeader", so ... I've extended the TRtcDataRequest component with new "Write", "WriteEx" and "PostMethod" methods in the RealThinClient SDK v7.102 update (one of the updates towards the next major RTC SDK release - v8.0) to make it possible to post requests wihout a content body - or a content body small enough to fit into clients memory - without implementing the OnBeginRequest event.
Best Regards, Danijel Tkalcec |