продолжаем тему Отправка POST-запроса - #18 от пользователя BlackRain666
Нужно отправить POST-запрос, прикрепив к нему тело.
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Net.HttpClient,
System.Net.URLClient,
System.Classes;
const
TWITCH_V5_ACCEPT : string = 'application/vnd.twitchtv.v5+json';
CLIENT_ID : string = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
function HttpPost(sURL : string; var res : string; aBody : string) : Integer;
var
c : THTTPClient;
r : IHTTPResponse;
i : Integer;
body : TStrings;
begin
c := THTTPClient.Create;
body := TStringList.Create;
body.Text := aBody;
try
r := c.Post(sURL, body, nil, nil, [tnameValuePair.Create('Client-ID', CLIENT_ID),
TNameValuePair.Create('Accept', TWITCH_V5_ACCEPT)]);
Result := r.StatusCode;
res := r.ContentAsString;
except
Result := 400;
end;
body.Free;
c.Free;
end;
procedure GetLiveStreamPlaylistURL(ChannelName : string);
const
_body : string = '{"operationName": "PlaybackAccessToken", "extensions": {"persistedQuery": '+
'{"version": 1, "sha256Hash": "0828119ded1c13477966434e15800ff57ddacf13ba1911c129dc2200705b0712"}}, '+
'"variables": {"isLive": true, "login": "<channame>", '+
'"isVod": false, "vodID": "", "playerType": "embed"}}';
var
t, body : string;
i : Integer;
begin
t := 'https://gql.twitch.tv/gql';
body := StringReplace(_body, '<channame>', ChannelName, []);
i := HttpPost(t, t, body);
Writeln(t);
read(t);
end;
begin
GetLiveStreamPlaylistURL('blackrain666666');
end.
выдаёт ошибку
{"error":"Bad Request","status":400,"message":"unable to read request body"}