1,593
社区成员
发帖
与我相关
我的任务
分享
procedure PostImage;
var
jsonObj: TJsonObject;
IdHttp: TIdHTTP;
postData: UTF8String;
resp: string;
reqStm: TStringStream;
begin
reqStm := TStringStream.Create('');
try
jsonObj := TJsonObject.Create;
try
jsonObj.AddPair('image_content','图片的base64内容');
jsonObj.AddPair('id','12345678');
postData := UTF8Encode(jsonObj.ToString);
reqStm.WriteBuffer(BytesOf(postData), Length(postData));
finally
FreeAndNil(jsonObj);
end;
IdHttp := TIdHTTP.Create;
try
try
IdHttp.AllowCookies := True;
IdHttp.ConnectTimeout := 30000;
IdHttp.Request.ContentType := 'application/json;charset=UTF-8';
IdHttp.Request.Accept := '*/*';
resp := IdHttp.Post('你的URL', reqStm);
if IdHttp.ResponseCode = 200 then
begin
//你的处理
end;
except ON E:Exception do
end;
finally
FreeAndNil(IdHttp);
end;
finally
FreeAndNil(reqStm);
end;
end;