RTC Forums
November 23, 2024, 10:04:31 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Simple 3rd party WebService with GET or POST  (Read 5792 times)
ISIGest
RTC Expired
*
Posts: 121


« 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
    begin
      Method := 'GET';
      Host := 'webservice.mysite.com';
      FileName := '';
      Clear;
      AsString['token'] := URL_Encode('mytoken');
      AsString['azione'] := URL_Encode('info');
      AsString['cardCode'] := URL_Encode('mycode');
    end;
    DataMain.HTTPDataRequest.Post();


How I can call and get the result with RTC HTTP Client?
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 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
Logged
ISIGest
RTC Expired
*
Posts: 121


« Reply #2 on: October 04, 2013, 03:34:26 PM »

Ok, but after ".Post()" method, nothing happens...
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: October 04, 2013, 03:37:49 PM »

Check this QuickStart lesson.

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
Logged
ISIGest
RTC Expired
*
Posts: 121


« Reply #4 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']??
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #5 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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #6 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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.026 seconds with 16 queries.