在delphi中选择菜单Project->Import Type library,然后分别把
Microsoft WinHTTP Services,version5.1(Version 5.1)
和
Microsoft Scripting Runtime (Version 1.0)
加到程序中 (点击Create Unit)
代码:
procedure TForm1.Button1Click(Sender: TObject);
var
http:WinhttpRequest;
fso:FileSystemObject;
fs:TextStream;
fil:File_;
url,user,password,path,xmlFile,statusStr:string;
begin
try
path:='c:\test.xml';
url:='https://test/test/test';
user:='test';
password:='test';
fso:=CreateComObject(CLASS_FileSystemObject) as FileSystemObject;
fil:=fso.GetFile(path);
fs:=fil.OpenAsTextStream(ForReading,TristateUseDefault);
xmlFile:=fs.ReadAll;
fs.Close;
http:=CreateComObject(CLASS_WinHttpRequest) as WinHttpRequest;
http.SetTimeouts(10000,10000,10000,10000);
http.Option[WinHttpRequestOption_SslErrorIgnoreFlags]:=13056;
http.Open('POST',url,EmptyParam);
http.SetRequestHeader('Content-Type','text/xml');
http.SetRequestHeader('Content-Length',inttostr(length(xmlFile)));
http.SetCredentials(user,password,0);
http.Send(xmlFile);
statusStr:=http.StatusText;
if statusStr='200' then
begin
ShowMessage('send success');
end
else
begin
ShowMessage('send failed');
end;
except
on err:EOleException do
begin
ShowMessage(err.Message);
end
else
begin
ShowMessage('other error!');
end;
end;
end;