Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to send POST data to a webserver?
#3
Thanks, I have modified the code as follows and tested it:
Code:
function TConfigCommHandler.UploadFirmware(FileName: string; URL: string): boolean;
var
 HTTP: TIdHTTP;
 Src: TIdMultipartFormDataStream;
begin
 Result := false;
 if not FileExists(FileName) then exit;
 HTTP := TIdHTTP.Create;
 try
   Src := TIdMultipartFormDataStream.Create;
   try
     Src.AddFile('update', FileName);
     try
       HTTP.Request.Username := FUserName;
       HTTP.Request.Password := FPassword;
       HTTP.AllowCookies := true; // * Added to try make the server accept update
       HTTP.Get(URL);  // * Added to read back form to simulate the action of a web browser
       HTTP.Post(URL, Src);  //Send the update file
       HTTP.Get(URL);  // * Added to retrieve the response
       Result := true;
     except
       on E: Exception do
         FLastError := 'Exception: ' + E.Message;
     end;
   finally
     Src.Free;;
   end;
 finally
   HTTP.Free;
 end;
end;
Still no update but I got a bit further, now the debug serial output shows a message "sleep disable" when the transfer starts and this is like it does when run from the browser too.

Quote:I suggest you run a packet sniffer (such as Wireshark) on your client machine and look at the actual HTTP traffic that a web browser generates vs what TIdHTTP generates when communicating with your IoT device. There is obviously going to be a difference between the two, but you are not going to see that just looking at code.
I have not used Wireshark to do any analysis. Many years ago I installed it but I did not really understand how to use it. There simply was too much stuff being shown. Is there a way to set it up to ONLY show traffic to and from a specific IP address?
I will start by downloading a more recent version in any case.

PS: I do have the C++ source code for the WebUpdater in the IoT device, only I am not a C++ coder so I cannot make much out of it. DS
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 BosseB - 05-01-2018, 06:30 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)