Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: How do I get my fingers in Rest parameters ???


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: Jun 12, 2017 8:13 PM Last Post By: Alexandre Machado
ib elfving

Posts: 33
Registered: 8/28/01
How do I get my fingers in Rest parameters ???  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 10, 2017 6:11 AM
Hi All,
I am running: Delphi XE5, Intraweb ver 14.0.52 (I know this i obsolete) in SA mode

I cannot read the json or xml parameter sent from a rest client to my intraweb application. I have looked every were for the data, but with no luck.

The parameters are send by a client program running an ip*works or indy rest component.

I am trying to read the attached json/xml in a custom contents handler.

Does anyone know how to get the input parameter ??

regards ib
Dan Barclay

Posts: 855
Registered: 11/9/03
Re: How do I get my fingers in Rest parameters ???  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 10, 2017 7:18 PM   in response to: ib elfving in response to: ib elfving
ib elfving wrote:
Hi All,
I am running: Delphi XE5, Intraweb ver 14.0.52 (I know this i obsolete) in SA mode

I cannot read the json or xml parameter sent from a rest client to my intraweb application. I have looked every were for the data, but with no luck.

The parameters are send by a client program running an ip*works or indy rest component.

I am trying to read the attached json/xml in a custom contents handler.

Does anyone know how to get the input parameter ??

Parameters will be in aRequest.Query (unparsed)

You may want to play with the sample project for CustomContentHandler.You can create parameter lists manually and explore the properties.

Dan
ib elfving

Posts: 33
Registered: 8/28/01
Re: How do I get my fingers in Rest parameters ???  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 11, 2017 8:53 AM   in response to: Dan Barclay in response to: Dan Barclay
Hi dan,
Thank you for your reply, but I am afraid that I cannot get it to work as you suggested.

I am using a customcontentshandler, and it works like a dream with "ordinary" html input params (e.g. http://someweb.com/json?task=hello), but with no luck when am i using a rest client.component

I am using the following code in the client:

wrest.PostData:=memo1.Text;
wrest.put(wurl.Text);

Memo1 contains {lines="hello world"}
wrest is a TipwREST component from ip*works (I have tried with indy, but with same result)
wurl.text is the URL

Besides wrest.put I have tried wrest.get and wrest.post but with same result

If I try and ordinary (not a rest component) GET with the json parameter added (e.g. http://someweb.com?{lines="hello world"} ) then the parameter will be in query as you stated, but not if you are using a rest client, then the parameter is missing from query - its empty.

regards ib
Jose Nilton Pace

Posts: 89
Registered: 5/15/98
Re: How do I get my fingers in Rest parameters ???  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 11, 2017 9:35 AM   in response to: ib elfving in response to: ib elfving
I'll give you a hint.
If you have browser testing turned on in your IW, it may be declining the client.
Ex: UnknownBrowser test.

on a IIS test cases i made, a browser name like this on a rest/client application and IW doesn´t recognize it as a browser:
Embarcadero+RESTClient/1.0 - 200 0 0 62

[]s, JNPace.
Alexandre Machado

Posts: 1,679
Registered: 8/10/13
Re: How do I get my fingers in Rest parameters ???  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 11, 2017 4:43 PM   in response to: ib elfving in response to: ib elfving
ib elfving wrote:
Hi All,
I am running: Delphi XE5, Intraweb ver 14.0.52 (I know this i obsolete) in SA mode

I cannot read the json or xml parameter sent from a rest client to my intraweb application. I have looked every were for the data, but with no luck.

The parameters are send by a client program running an ip*works or indy rest component.

I am trying to read the attached json/xml in a custom contents handler.

Does anyone know how to get the input parameter ??

regards ib

I believe you have a POST request which "content-type" is application/json or application/xml, correct?

By default, IntraWeb only parses and stores a few content types. All the others are discarded.

In this case, you have to register this content type to be received by IntraWeb application. This demo shows how to do it:

https://iwdemos.codeplex.com/SourceControl/latest#Atozed Demos/XIV/Delphi/PostDataDemo/

Please notice the code we use in ServerController to register XML content type:


uses IW.Parser.Files {use IW.Parser.UTF8 for older versions};
 
procedure TIWServerController.IWServerControllerBaseConfig(Sender: TObject);
begin
  RegisterContentType('application/xml');
end;


And then, this is how the content parser gets the XML from a file object (THttpFile):


function TContentXML.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication;
  aParams: TStrings): boolean;
var
  xFile: THttpFile;
  fs: TFileStream;
  xml: TStringStream;
begin
  Result := False;
  if aRequest.Files.Count = 1 then begin
    xFile := THttpFile(aRequest.Files[0]);
    fs := TFileStream.Create(xFile.TempPathName, fmOpenRead or fmShareDenyNone);
    xml := TStringStream.Create;
    try
      xml.CopyFrom(fs, 0);
      aReply.WriteString(ClassName + '.Execute - Content received: ' + xml.DataString);
      Result := True;
    finally
      xml.Free;
      fs.Free;
    end;
  end;
end;
 


along with source code files you also can find a file named "How to simulate a request using Firefox Poster addon" which can give you some hints on how to use Firefox Poster add on to simulate those types of requests (very handy when you don't have the client or its setup is complicated).

Poster add on can be found here: https://addons.mozilla.org/en-us/firefox/addon/poster/

There are several add ons like this for different browsers. I use Poster myself because I find it simple and convenient.

Edited by: Alexandre Machado on Jun 11, 2017 4:44 PM
ib elfving

Posts: 33
Registered: 8/28/01
Re: How do I get my fingers in Rest parameters ???  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 12, 2017 7:13 PM   in response to: Alexandre Machado in response to: Alexandre Machado
Hi Alexandre,
Your reply was spot on. Thank you, I've been struggling with this problem for a long time and now it is solved. The solution is working like a dream.

The input parameter from a rest client is "posted" even if you use "put" in the client, so your advice with the Thttpfile was spot on. Thank you very much.

regards ib
Alexandre Machado

Posts: 1,679
Registered: 8/10/13
Re: How do I get my fingers in Rest parameters ???  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 12, 2017 8:12 PM   in response to: ib elfving in response to: ib elfving
ib elfving wrote:
Hi Alexandre,
Your reply was spot on. Thank you, I've been struggling with this problem for a long time and now it is solved. The solution is working like a dream.

The input parameter from a rest client is "posted" even if you use "put" in the client, so your advice with the Thttpfile was spot on. Thank you very much.

regards ib

Great! Thanks for the feedback!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02