Delphi idHTTP上传文件

时间:2015-06-28 10:10:10

标签: delphi indy idhttp

我尝试使用标准格式将文件上传到sharepoint 2013。我使用TIdHTTPTIdSSLIOHandlerSocketOpenSSLTIdLogDebug个组件:

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;

在事件TIDDebugLog.OnReceive上收到错误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

我需要修复此错误?

0 个答案:

没有答案