Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var
- GlobalCookieManager : TIdCookieManager;
- // ...
- //------------------------------------------------------------------------//
- procedure LoginToServer(TheLogin, ThePassword : String);
- var
- IdHTTP : TIdHTTP;
- ParamList : TStringList;
- begin
- IdHTTP := TIdHTTP.Create(nil);
- try
- // First reset CookieManager
- FreeAndNil(GlobalCookieManager);
- GlobalCookieManager := TIdCookieManager.Create(nil);
- IdHTTP.CookieManager := GlobalCookieManager;
- ParamList := TStringList.Create;
- try
- ParamList.Values['login'] := TheLogin;
- ParamList.Values['password'] := ThePassword;
- IdHTTP.Post('http://localhost/my-app/login.php', ParamList);
- finally
- FreeAndNil(ParamList);
- end; // try/finally
- finally
- FreeAndNil(IdHTTP);
- end; // try/finally
- end;
- //------------------------------------------------------------------------//
- procedure TUploadThread.UploadFile(FileName : String);
- var
- IdHTTP : TIdHTTP;
- CookieMgr : TIdCookieManager;
- RangeStream : TIdHTTPRangeStream;
- StartPos : Int64;
- begin
- IdHTTP := TIdHTTP.Create(nil);
- try
- CookieMgr := TIdCookieManager.Create(nil);
- IdHTTP.CookieManager := CookieMgr;
- with IdHTTP.Request.RawHeaders do
- begin
- Clear;
- for i := 0 to GlobalCookieManager.CookieCollection.Count - 1 do
- Add('Cookie' + NameValueSeparator + GlobalCookieManager.CookieCollection.Cookies[i].CookieText);
- end; // with
- TheFile := TFileStream.Create(FileName, fmOpenRead OR fmShareDenyWrite);
- RangeStream := TIdHTTPRangeStream.Create(TheFile, StartPos, -1, True);
- if (RangeStream.ResponseCode = 206) then
- begin
- try
- IdHTTP.Post('http://localhost/my-app/upload.php', RangeStream);
- finally
- FreeAndNil(RangeStream);
- end; // try/finally
- end;
- finally
- FreeAndNil(IdHTTP);
- end; // try/finally
- end;
- //------------------------------------------------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement