Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: HttpClientComponent TNetHTTPRequest fails to pass data file


This question is answered.


Permlink Replies: 8 - Last Post: Apr 8, 2015 8:02 PM Last Post By: Remy Lebeau (Te...
Erick Engelke

Posts: 101
Registered: 12/5/02
HttpClientComponent TNetHTTPRequest fails to pass data file  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 8, 2015 3:17 PM
Hi,

I'm excitedly using XE8 Delphi and wanted to use the new HttpClientComponent.TNetHTTPRequest
Post or Put to update data from my clients. In the past I used Indy, but the native HTTPS support
will be wonderful.

Post() and Put() work, but looking at the server side, including the http_access_log on Apache, the request to the server doesn't include the supposed-to-be-included file.

In my test code I have tried memory stream (position reset to zero first)

writeln( DataModule1.NetHTTPRequest1.Put( url, memorystream ).ContentAsString);

I tried passing a filename in a string (system.string)
writeln( DataModule1.NetHTTPRequest1.Put( url, filename ).ContentAsString);

and I tried
writeln( DataModule1.NetHTTPRequest1.Put( url, stringlist).ContentAsString);

The request is always about 80 bytes, whereas the file I want to include is 5kB.

What gives????

Thanks for any hint, I've been banging against a wall
Erick

--
Erick Engelke
Director, Engineering Computing
University of Waterloo

--
Erick Engelke
Director, Engineering Computing
University of Waterloo
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: HttpClientComponent TNetHTTPRequest fails to pass data file
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 8, 2015 3:38 PM   in response to: Erick Engelke in response to: Erick Engelke
Erick wrote:

In the past I used Indy, but the native HTTPS support will be wonderful.

You do know that Indy supports HTTPS, right? And that Embarcadero's network
technologies are largely built on top of Indy? Also, there was an update
to Indy a few months ago to support HTTPS almost "out of the box" if you
don't need to customize any SSL settings (see http://indyproject.org/Sockets/Blogs/ChangeLog/20141222.aspx).

--
Remy Lebeau (TeamB)
Erick Engelke

Posts: 101
Registered: 12/5/02
Re: HttpClientComponent TNetHTTPRequest fails to pass data file  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 8, 2015 4:09 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Erick wrote:

In the past I used Indy, but the native HTTPS support will be wonderful.

You do know that Indy supports HTTPS, right? And that Embarcadero's network
technologies are largely built on top of Indy? Also, there was an update
to Indy a few months ago to support HTTPS almost "out of the box" if you
don't need to customize any SSL settings (see http://indyproject.org/Sockets/Blogs/ChangeLog/20141222.aspx).

Thanks Remy,

I was hoping to be more portable to other devices, and maybe not require an additional DLL in the install. I'll play for a while longer before reverting to my old libs.

Erick
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: HttpClientComponent TNetHTTPRequest fails to pass data file  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 8, 2015 5:35 PM   in response to: Erick Engelke in response to: Erick Engelke
Erick wrote:

I was hoping to be more portable to other devices

You can keep using Indy for that, as it is cross-platform and does support
all of Delphi's target OS platforms.

and maybe not require an additional DLL in the install.

Switching to Embarcadero's new HttpClient API would not avoid that dependancy.

--
Remy Lebeau (TeamB)
Eli M

Posts: 1,346
Registered: 11/9/13
Re: HttpClientComponent TNetHTTPRequest fails to pass data file  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 8, 2015 7:50 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
The issue with the Indy based TRESTClient in Delphi XE7 is that SSL+GZIP crashes out on IOS. I have a demo project if you like. Embarcadero was not able to solve it with a support incident.

Remy Lebeau (TeamB) wrote:
You can keep using Indy for that, as it is cross-platform and does support
all of Delphi's target OS platforms.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: HttpClientComponent TNetHTTPRequest fails to pass data file  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 8, 2015 8:02 PM   in response to: Eli M in response to: Eli M
Eli wrote:

The issue with the Indy based TRESTClient in Delphi XE7 is
that SSL+GZIP crashes out on IOS.

I don't know anything about that, but I do know that SSL in general works
fine on iOS, so maybe it is a bug in Embarcadero's TRESTClient wrapper rather
than in Indy itself.

--
Remy Lebeau (TeamB)
Eli M

Posts: 1,346
Registered: 11/9/13
Re: HttpClientComponent TNetHTTPRequest fails to pass data file
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 8, 2015 4:27 PM   in response to: Erick Engelke in response to: Erick Engelke
Uses
System.Net.Mime;
 
procedure TForm1.Button1Click(Sender: TObject);
var
MS: TStringStream;
MPFD: TMultiPartFormData;
begin
MS := TStringStream.Create;
MS.WriteString('Firemonkey is awesome!');
MS.SaveToFile(ExtractFilePath(ParamStr(0)) + 'test.txt');
MS.Clear;
MS.Seek(0,0);
MPFD := TMultiPartFormData.Create;
MPFD.AddFile('file',ExtractFilePath(ParamStr(0)) + 'test.txt');
NetHTTPRequest1.Post( 'http://www.posttestserver.com/post.php?dump&dir=xe8', MPFD, MS );
MS.Seek(0,0);
Memo1.Lines.Text := MS.DataString;
MS.Free;
MPFD.Free;
end;
Erick Engelke

Posts: 101
Registered: 12/5/02
Re: HttpClientComponent TNetHTTPRequest fails to pass data file  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 8, 2015 5:04 PM   in response to: Eli M in response to: Eli M
Eli M wrote:
{code}
Uses
System.Net.Mime;

Thanks. Perfect.
Erick
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: HttpClientComponent TNetHTTPRequest fails to pass data file  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 8, 2015 5:38 PM   in response to: Eli M in response to: Eli M
Eli wrote:

MS := TStringStream.Create;
MS.WriteString('Firemonkey is awesome!');

You can combine those statements using a different constructor:

MS := TStringStream.Create('Firemonkey is awesome!');


MS.SaveToFile(ExtractFilePath(ParamStr(0)) + 'test.txt');

You did not seek back to Position 0 before calling SaveToFile().

MS.Clear;
MS.Seek(0,0);

Seek() after Clear() is redundant.

MS.Seek(0,0);
Memo1.Lines.Text := MS.DataString;

The DataString property returns the content of the entire stream, so you
do not need to seek back to Position 0 first.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02