Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to send POST data to a webserver?
#6
(05-01-2018, 07:43 PM)BosseB Wrote: Is there something here that I should add into the TIdHTTP component before using POST?

You should add the "Referer" request header. You can use the TIdHTTP.Request.Referer property for that:

Code:
HTTP.Request.Referer := 'http://192.168.119.249/firmware';

That header tells the server which URL is submitting the webform to the server. Some servers do perform Referer validation to make sure only valid Referers can send in data.

(05-01-2018, 07:43 PM)BosseB Wrote:
Code:
HTTP.Request.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';

You don't really need that header. All it is doing is telling the server that the browser prefers (X)HTML and XML, but will still accept anything. Indy's default Request.Accept property value will suffice.

(05-01-2018, 07:43 PM)BosseB Wrote:
Code:
HTTP.Request.AcceptEncoding := 'gzip, deflate';

That header, you definitely SHOULD NOT set manually. It is telling the server that the browser will accept compressed responses. TIdHTTP handles compression but ONLY when its Compressor property is configured. Let TIdHTTP manage its Request.AcceptEncoding property for you, based on TIdHTTP's actual capabilities.

(05-01-2018, 07:43 PM)BosseB Wrote:
Code:
HTTP.Request.AcceptLanguage := 'en-US,en;q=0.5';

You don't need that.

(05-01-2018, 07:43 PM)BosseB Wrote:
Code:
HTTP.Request.ContentType := 'multipart/form-data;';

You don't need to set the Request.ContentType property manually when calling Post(). It will assign an appropriate ContentType for you, depending on the type of data being posted.

(05-01-2018, 07:43 PM)BosseB Wrote:
Code:
HTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0';

That is optional, depending on if/how the server reacts to different User-Agent strings.

(05-01-2018, 07:43 PM)BosseB Wrote: I have noted that the Content-Length is always bigger than the actual file size and the difference seems to be close to the same but not exactly so...

The "Content-Length" reflects the total size of the entire data that is being posted. It includes the MIME data that surrounds your file data. You are not posting just the file by itself, there is other data being posted, too (ie, the file's name and media type).

(05-01-2018, 07:43 PM)BosseB Wrote: I was unable to use Wireshark, could not even find how to set a filter for the IP address or start capturing...

The filter is right there at the top of the main window. It says "Filter:" next to it.

You use the "Capture" menu to choose which network interface(s) to capture from and with what settings, and to start/stop captures.

I suggest you read Wireshark's documentation, particularly the User's Guide.

Reply


Messages In This Thread
How to send POST data to a webserver? - by BosseB - 04-30-2018, 09:56 PM
RE: How to send POST data to a webserver? - by rlebeau - 05-01-2018, 09:18 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)