Delphi idHTTP upload file

2k views Asked by At

I try to upload file to sharepoint 2013 using standart form. I use TIdHTTP, TIdSSLIOHandlerSocketOpenSSL and TIdLogDebug components:

procedure TForm1.Button3Click(Sender: TObject);
var
  DS: TIdMultipartFormDataStream;
begin
  DS := TIdMultiPartFormDataStream.Create;
  try
    DS.AddFile('ctl00$PlaceHolderMain$UploadDocumentSection$ctl05$InputFile', 'C:\1.txt', 'text/html');
    IdHTTP1.Request.Username := 'user';
    IdHTTP1.Request.Password := 'pwd';
    IdHTTP1.Post('h***s://mysite.com/sites/studybi/_layouts/15/UploadEx.aspx?List=%7bBFE10E5D-E96F-4CF3-B42A-A17AE987161D%7d&RootFolder=&IsDlg=1', DS);
  finally
    DS.Free;
  end;
end;

procedure TForm1.IdHTTP1SelectAuthorization(Sender: TObject;
  var AuthenticationClass: TIdAuthenticationClass; AuthInfo: TIdHeaderList);
begin
  AuthenticationClass := TIdNTLMAuthentication;
end;

On event TIDDebugLog.OnReceive get error 401 Unauthorized:

HTTP/1.1 401 Unauthorized
Cache-Control: private
Content-Length: 16
Content-Type: text/plain; charset=utf-8
SPRequestGuid: 6d55159d-3f0a-d03f-d7bc-9c7f506c0196
request-id: 6d55159d-3f0a-d03f-d7bc-9c7f506c0196
X-FRAME-OPTIONS: SAMEORIGIN
SPRequestDuration: 53
SPIisLatency: 5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
WWW-Authenticate: NTLM
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
MicrosoftSharePointTeamServices: 15.0.0.4551
Date: Tue, 30 Jun 2015 06:31:41 GMT
Connection: close

What I need to fix this error?

0

There are 0 answers