Recent

Author Topic: TFPHTTPClient get ERROR 414 Request-URI Too Large from server  (Read 2710 times)

DidaJI

  • New Member
  • *
  • Posts: 32
TFPHTTPClient get ERROR 414 Request-URI Too Large from server
« on: January 14, 2020, 07:00:46 am »
Hi,
I have a problem with communication with the server via the TFHTTPClient component. PHP scripts are running on the server side. I use the POST method and as long as the request size is less than 8192 bytes, everything is OK. However, if the request grows to a size above 8192 bytes (sending photos in BASE64 format), the server returns an error: 414 Request-URI Too Large. On the server (Apache) I have set the POST query size to 32MB.

Anyone know how to solve it? I need to send a request of about 50KB.

Thank's: Zdenek.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: TFPHTTPClient get ERROR 414 Request-URI Too Large from server
« Reply #1 on: January 14, 2020, 07:17:06 am »
Perhaps the web browser you're using has a size limit?

DidaJI

  • New Member
  • *
  • Posts: 32
Re: TFPHTTPClient get ERROR 414 Request-URI Too Large from server
« Reply #2 on: January 14, 2020, 07:47:39 am »
If I try to call php script on server from a browser and send it a 50KB request, it normally works. It's not just from the program.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: TFPHTTPClient get ERROR 414 Request-URI Too Large from server
« Reply #3 on: January 14, 2020, 08:06:39 am »
What does the web server log show?

DidaJI

  • New Member
  • *
  • Posts: 32
Re: TFPHTTPClient get ERROR 414 Request-URI Too Large from server
« Reply #4 on: January 14, 2020, 08:47:19 am »
I use Synology NAS as a server. There is nothing about this query in the Apache error log, and the Acces log does not know where to find the Synology.
I would have to install Apache on another PC and try it out there. Then I get to all the logs.

DidaJI

  • New Member
  • *
  • Posts: 32
Re: TFPHTTPClient get ERROR 414 Request-URI Too Large from server
« Reply #5 on: January 14, 2020, 10:26:32 am »
The problem seems to be that I am entering data directly into the url and it can only be 8192 characters long.

Simplified:

url := 'http://192.168.64.2/test/' + 'action.php?ID=1' + '&data=' + Base64Str;
HTTPClient := TFPHTTPClient.Create(nil);
html := HTTPClient.Post(url);     

This works if Base64Str is less than 8192 bytes.
In the case of longer data, this will probably have to be entered somehow other than directly into the url.
Would anyone know how?


trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: TFPHTTPClient get ERROR 414 Request-URI Too Large from server
« Reply #6 on: January 14, 2020, 12:49:55 pm »

DidaJI

  • New Member
  • *
  • Posts: 32
Re: TFPHTTPClient get ERROR 414 Request-URI Too Large from server
« Reply #7 on: January 14, 2020, 02:29:22 pm »
So it works, it was necessary to use FormPost and pass the data as a parameter and not in the URL.

hedmondjohn

  • Newbie
  • Posts: 1
Re: TFPHTTPClient get ERROR 414 Request-URI Too Large from server
« Reply #8 on: December 28, 2022, 08:59:17 am »
This rare condition is only likely to occur when a client has improperly converted a POST request to a GET request with long query information. The HTTP 414 URI Too Long response status code indicates that the URI(Uniform Resource Identifier) requested by the client is longer than the server is willing to interpret.

To resolve this problem :

By POST request: Convert query string to json object and sent to API request with POST.

By GET request: Max length of request is depend on sever side as well as client side. Most webserver have limit 8k which is configurable. On the client side the different browser has different limit. The browser IE and Safari limit to 2k, Opera 4k and Firefox 8k. This means that the max length for the GET request is 8k and min request length is 2k.

If exceed the request max length then the request truncated outside the limit by web server or browser without any warning. Some server truncated request data but the some server reject it because of data lose and they will return with response code 414

Under Apache, the limit is a configurable value, LimitRequestLine. If you want to increase URL limit to 5000 characters (bytes), add the following lines to your server configuration or virtual host file.

LimitRequestLine 5000

If you want to increase maximum header length supported by Apache to 3000 characters, then add the following line.

LimitRequestFieldSize 3000

« Last Edit: December 31, 2022, 05:20:03 pm by marcov »

Thaddy

  • Hero Member
  • *****
  • Posts: 14214
  • Probably until I exterminate Putin.
Re: TFPHTTPClient get ERROR 414 Request-URI Too Large from server
« Reply #9 on: December 28, 2022, 09:12:45 am »
The payload should be in TfpHttpClient.RequestBody before you post. Indeed NOT in the URL.
There are no limitations other than the protocol may describe.
Within that constraint the requestBody takes a TStream of any size.
Also, the requestHeader should contain the content type. e.g. application/json etc, otherwise the protocol can not handle the body correctly.
« Last Edit: December 28, 2022, 09:24:20 am by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018