Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-03

Brook-fpWeb POST without fields

11 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, a CGI I'm making needs to receive a POST message containing binary data, but it doesn't contain fields, so I cannot access that data from my program.

I'm using BrookFramework but if you find a solution using fcl-web is ok.

Here's the header captured in google chrome:

POST /index/ HTTP/1.1
Host: 127.0.0.1:8080
Connection: keep-alive
Content-Length: 108527
Origin: http://127.0.0.1:8080
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1897.2 Safari/537.36 Content-Type: application/vnd.oasis.opendocument.text Accept: */*
Referer: http://127.0.0.1:8080/webodf/programs/editor/src-localeditor.html Accept-Encoding: gzip,deflate,sdch
Accept-Language: es-419,es;q=0.8,en;q=0.6

Regards,

Reply by email

silvioprog
to Leonardo M. Ramé

2014-03-20 14:59 GMT-03:00 Leonardo M. Ram? :

Show quoted text 25 lines
Hi, a CGI I'm making needs to receive a POST message containing binary data, but it doesn't contain fields, so I cannot access that data from my program. I'm using BrookFramework but if you find a solution using fcl-web is ok. Here's the header captured in google chrome: POST /index/ HTTP/1.1 Host: 127.0.0.1:8080 Connection: keep-alive Content-Length: 108527 Origin: http://127.0.0.1:8080 User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1897.2 Safari/537.36 Content-Type: application/vnd.oasis.opendocument.text Accept: */* Referer: http://127.0.0.1:8080/webodf/programs/editor/src-localeditor.html Accept-Encoding: gzip,deflate,sdch Accept-Language: es-419,es;q=0.8,en;q=0.6 Regards, -- Leonardo M. Ram? http://leonardorame.blogspot.com

Hello,

In new Brook 3.0 (from trunk), if your request use form-data, you can access the streams via Files property, e.g:

Files.Files[0].Stream;

But, using the "application/vnd.oasis.opendocument.text" content type, I think that you need to use BrookHttpClient.

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140320/e447163e/attachment.html>

Reply by email

Leonardo M. Ramé
to silvioprog
silvioprog wrote 39 lines
2014-03-20 14:59 GMT-03:00 Leonardo M. Ram? : > Hi, a CGI I'm making needs to receive a POST message containing binary > data, but it doesn't contain fields, so I cannot access that data from > my program. > > I'm using BrookFramework but if you find a solution using fcl-web is ok. > > Here's the header captured in google chrome: > > POST /index/ HTTP/1.1 > Host: 127.0.0.1:8080 > Connection: keep-alive > Content-Length: 108527 > Origin: http://127.0.0.1:8080 > User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, > like Gecko) Chrome/35.0.1897.2 Safari/537.36 > Content-Type: application/vnd.oasis.opendocument.text > Accept: */* > Referer: http://127.0.0.1:8080/webodf/programs/editor/src-localeditor.html > Accept-Encoding: gzip,deflate,sdch > Accept-Language: es-419,es;q=0.8,en;q=0.6 > > Regards, > -- > Leonardo M. Ram? > http://leonardorame.blogspot.com Hello, In new Brook 3.0 (from trunk), if your request use form-data, you can access the streams via Files property, e.g: Files.Files[0].Stream; But, using the "application/vnd.oasis.opendocument.text" content type, I think that you need to use BrookHttpClient.

Well, aparently there are no files in the request, because Files array is empty.

Regarding BrookHttpClient, isn't it client for http requests?, I need to parse a request from a client, my program is the server.

Regards,

Reply by email

silvioprog
to silvioprog: 2014-03-20 14:59 GMT-03:00 Leonardo M. Ram? : In new Brook 3.0 (from trunk), if your…

Oops...

2014-03-20 15:12 GMT-03:00 silvioprog :
[...]

Files.Files[0].Stream;

*Files[0].Stream;*

But, using the "application/vnd.oasis.opendocument.text" content type, I think that you need to use BrookHttpClient.

Ie, to download your binary data, eg:
https://github.com/silvioprog/brookframework/blob/master/demos/http/client/project1.lpr .

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140320/5980a14c/attachment.html>

Reply by email

silvioprog
to silvioprog

"Well, aparently there are no files in the request, because Files array is empty.

Regarding BrookHttpClient, isn't it client for http requests?, I need to parse a request from a client, my program is the server. "

Unfortunately I did not received your reply on my email, I saw that you responded after accessing the topic link. :/

But the binary will downloaded from other URL or it will available from your own app? In first case, you need download it via client in your server and after display it to client, in second case, seems that you need to use content-disposition. If is second case, I can do easily a small sample of "content-disposition" for you too.

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140320/581966e5/attachment.html>

Reply by email

Leonardo M. Ramé
to silvioprog: "Well, aparently there are no files in the request, because Files array is empty.…
silvioprog wrote 8 lines
"Well, aparently there are no files in the request, because Files array is empty. Regarding BrookHttpClient, isn't it client for http requests?, I need to parse a request from a client, my program is the server. " Unfortunately I did not received your reply on my email, I saw that you responded after accessing the topic link. :/

As far as I remember I just hit "g" on mutt, then answered your email :)

Show quoted text 6 lines
But the binary will downloaded from other URL or it will available from your own app? In first case, you need download it via client in your server and after display it to client, in second case, seems that you need to use content-disposition. If is second case, I can do easily a small sample of "content-disposition" for you too.

Let me clarify this. My app is a CGI program running on an Apache server, the client is a javascript file running on the same server.

The relevant part of the client javascript is this:

  blob = new Blob([data.buffer], {type: mimetype});
  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'http://127.0.0.1:8080/cgi-bin/test', false);
  xhr.send(blob);

As you can see, "blob" is an object containing a typed array that I'm trying to send to the server using a POST command.

Regards,

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt: What is the problem ? TRequest.Content will contain the binary data. Michael.
Michael Van Canneyt wrote 11 lines
On Thu, 20 Mar 2014, Leonardo M. Ram? wrote: >Hi, a CGI I'm making needs to receive a POST message containing binary >data, but it doesn't contain fields, so I cannot access that data from >my program. What is the problem ? TRequest.Content will contain the binary data. Michael.

Hehe, you are right, there's the content.

Thank you again Michael.

Regards,

Reply by email

silvioprog
to Leonardo M. Ramé: As far as I remember I just hit "g" on mutt, then answered your email :) Let me clarify…

2014-03-20 16:07 GMT-03:00 Leonardo M. Ram? :
[...]

Show quoted text 12 lines
Let me clarify this. My app is a CGI program running on an Apache server, the client is a javascript file running on the same server. The relevant part of the client javascript is this: blob = new Blob([data.buffer], {type: mimetype}); var xhr = new XMLHttpRequest(); xhr.open('POST', 'http://127.0.0.1:8080/cgi-bin/test', false); xhr.send(blob); As you can see, "blob" is an object containing a typed array that I'm trying to send to the server using a POST command.

So you need to send it via form-data. Using the form-data you will receive your buffer in Files property (it points to the "Request.Files" property of FCL-Web).

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140320/05e3068b/attachment.html>

Reply by email

Leonardo M. Ramé
to silvioprog
silvioprog wrote 21 lines
2014-03-20 16:07 GMT-03:00 Leonardo M. Ram? : [...] > Let me clarify this. My app is a CGI program running on an Apache > server, the client is a javascript file running on the same server. > > The relevant part of the client javascript is this: > > blob = new Blob([data.buffer], {type: mimetype}); > var xhr = new XMLHttpRequest(); > xhr.open('POST', 'http://127.0.0.1:8080/cgi-bin/test', false); > xhr.send(blob); > > As you can see, "blob" is an object containing a typed array that I'm > trying to send to the server using a POST command. So you need to send it via form-data. Using the form-data you will receive your buffer in Files property (it points to the "Request.Files" property of FCL-Web).

Silvio, here's the solution. Just create a Post handler, then save TheRequest.Content string as a TFileStream:

procedure TIndex.Post;
var
  lStream: TFileStream;
begin
  lStream := TFileStream.Create('output.odf', fmCreate);
  try
    lStream.Write(TheRequest.Content[1], TheRequest.ContentLength);
  finally
    lStream.Free;
  end;
end;

Reply by email

silvioprog
to Leonardo M. Ramé

2014-03-20 16:28 GMT-03:00 Leonardo M. Ram? :
[...]

Show quoted text 14 lines
Silvio, here's the solution. Just create a Post handler, then save TheRequest.Content string as a TFileStream: procedure TIndex.Post; var lStream: TFileStream; begin lStream := TFileStream.Create('output.odf', fmCreate); try lStream.Write(TheRequest.Content[1], TheRequest.ContentLength); finally lStream.Free; end; end;

Oops, sorry for my confusion. Until then I had not understood the problem hehe...

Michael is right, the Content property will get your buffer as stream! :)

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140320/afd050a2/attachment.html>

Reply by email