Einzelnen Beitrag anzeigen

ScharfeMietze

Registriert seit: 5. Mär 2014
165 Beiträge
 
Delphi 10.2 Tokyo Architect
 
#1

Discord "message": "Cannot send an empty message", "code": 50006

  Alt 13. Feb 2020, 14:24
Hey Leute,
ich scheitre gerade an Discord. Ich habe einen Webhook erstellt.
Ich schaffe es aber nicht eine einfache Message zu senden.
Weder mit net noch mit Indy
Json String ist valide und der Content type ist auf 'application/json'
Weder mit einem Stream noch mit einer TStringlist. funktioniert es.

Der Code
Delphi-Quellcode:
procedure TForm5.btn1Click(Sender: TObject);
var
  LsList: TStringList;
  LResponse:string;
  LSStream: TStringStream;
const
  LContent = '{"content": "Test"}';
begin
LsList := TStringList.Create;
LSStream:= TStringStream.Create(LContent, TEncoding.UTF8);
  try
  LResponse:= nthtpclnt1.get(FUrl).ContentAsString();
  mmo1.Lines.Add('0 ' + LResponse);

  LsList.DefaultEncoding.UTF8;
  LsList.Add(LContent);
  nthtpclnt1.ContentType:= 'application/json';


  LResponse:= nthtpclnt1.Post(FUrl,LSStream).ContentAsString();
  mmo1.Lines.Add('1 ' + LResponse);
  LResponse:= nthtpclnt1.Post(FUrl,LsList).ContentAsString();
  mmo1.Lines.Add('2 ' + LResponse);
  finally
    LsList.Free;
    LSStream.Free;
  end; // try
end;
btn2
Delphi-Quellcode:
procedure TForm5.btn2Click(Sender: TObject);
var
  params: TStringStream;
  LIndy: TIdHTTP;
  LResponse:string;
const
  LContent = '{"content": "Test"}';
begin
  LIndy:= TIdHTTP.Create();
  params := TStringStream.Create(LContent, TEncoding.UTF8);
  try
    LIndy.Request.ContentType := 'application/json';
    LIndy.Request.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36';
    LResponse:= LIndy.Post(FUrl, params);
  finally
    LIndy.Free;
    params.Free;
  end;
  mmo1.Lines.Add('3 ' + LResponse);
end;

Die Antworten
Delphi-Quellcode:
0 {"type": 1, "id": "67713562xxxxx", "name": "Test", "avatar": null, "channel_id": "677135529xxxx", "guild_id": "640861371927xxxxx", "token": "JlWiT1BTTWBmMxzbjoyEdeuIBv8A8Vj3bPBJxxxxxxxx"}
1
2 {"message": "Cannot send an empty message", "code": 50006}
3
Wahrscheinlich ist irgendwo ein simpler Fehler den ich gerade übersehe.
Sieht wer meinen Fehler?
Dank die SM

Geändert von ScharfeMietze (13. Feb 2020 um 14:29 Uhr)
  Mit Zitat antworten Zitat