Help (Newbie) lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- N3 · 2023-01-20 14:06 The following procedure fails to send a pushover event. What am I doing wrong? This was pulled from OpenAI. It get the error message that it couldn't send. procedure start_pushover; const   PUSHOVER_URL = 'https://api.pushover.net/1/messages.json'; var    http: THTTPSend;    json: TJSONObject;    jsonData: TStringList;    response: TStringList; begin      http := THTTPSend.Create;   try     json := TJSONObject.Create;     try       json.Add('token', patoken);       json.Add('user', putoken);       json.Add('device', pdevice);       json.Add('message', 'This is a test');       jsonData := TStringList.Create;       try         jsonData.Add(json.AsJSON);         if http.HTTPMethod('POST', PUSHOVER_URL) then         begin           response := TStringList.Create;           try             response.LoadFromStream(http.Document);             Writeln(response.Text);           finally             response.Free;           end;         end         else         begin           Writeln('Error: ', http.ResultString);         end;       finally         jsonData.Free;       end;     finally       json.Free;     end;   finally     http.Free;   end; end; ---------------------------------------------------------------------- KodeZwerg · 2023-01-20 14:57 Quote from: N3 on January 20, 2023, 03:06:50 pmWhat am I doing wrong? This was pulled from OpenAI. It get the error message that it couldn't send.Tell your OpenAI that it not work with your error message that we miss. ---------------------------------------------------------------------- Thaddy · 2023-01-20 15:14 Yoou did not tell us which framework you use. I suspect it is Indy. ---------------------------------------------------------------------- N3 · 2023-01-20 15:17 Synapse ---------------------------------------------------------------------- alpine · 2023-01-20 15:27 @N3 No, it is your fault you didn't explained to OpenAI how to give you the right procedure ---------------------------------------------------------------------- paweld · 2023-01-20 15:33 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);const  PUSHOVER_URL = 'https://api.pushover.net/1/messages.json';var  http: THTTPSend;  json: TJSONObject;  ss: TStringStream;begin  http := THTTPSend.Create;  json := TJSONObject.Create;  json.Add('token', 'patoken');  json.Add('user', 'putoken');  json.Add('device', 'pdevice');  json.Add('message', 'This is a test');   ss := TStringStream.Create(json.AsJSON);     http.Document.CopyFrom(ss, 0); // set json as request body  try    if http.HTTPMethod('POST', PUSHOVER_URL) then    begin      ss.Clear;      ss.CopyFrom(http.Document, 0);      Memo1.Lines.Add(ss.DataString);  end    else    begin      Memo1.Lines.Add('Error: ' + http.ResultString);    end;  finally    ss.Free;    json.Free;    http.Free;  end;end; ---------------------------------------------------------------------- Bogen85 · 2023-01-20 16:05 Quote from: alpine on January 20, 2023, 04:27:09 pm@N3 No, it is your fault you didn't explained to OpenAI how to give you the right procedure  Totally... OpenAI works on prompt and completion... you have to prompt it correctly to get the desired completion... ---------------------------------------------------------------------- Thaddy · 2023-01-20 17:34 I asked a better question and got a better answer. The error response is correct since I did not bother to register for a key:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i { This example will send a request to the given URL and then print the response body.} program PushoverExample; {$mode objfpc} uses  fpjson,  fpHTTPClient,  opensslsockets,  SysUtils; var  HTTPClient: TFPHTTPClient;  JSONRequest, JSONResponse: TJSONObject;  RespBody: string;begin  // Create HTTP Client  HTTPClient := TFPHTTPClient.Create(nil);   // Create request  JSONRequest := TJSONObject.Create;  JSONRequest.Add('token','sometoken');  JSONRequest.Add('user','someuser');  JSONRequest.Add('message','Hello World!');   // Make request  RespBody := HTTPClient.FormPost('https://api.pushover.net/1/messages.json', JSONRequest.AsJSON);   // Print response body  writeln(RespBody);   // Free resources  JSONRequest.Free;  HTTPClient.Free;end. Please see that this only uses Freepascal provided libraries and nothing third-party. Except for the comment this is all OpenAI generated code. I was more precise in asking to use only standard libraries and that TfpHttpCient should be used. Note that if you fill in the user credentials properly, this code works even better!