C
coolnet
Unregistered / Unconfirmed
GUEST, unregistred user!
我用D6带的Indy的HTTPClient,在ContentType中设了multipart/form-data,但Post文件后
发现发送的时候没有boundary,即是以一个整体发过去的,与通过IE浏览器发送文件相比,
ContentType中少了boundary和其他的一些信息,发送的信息也没有像IE那样用boundary
分割开来,现在是发送一个文件,如果想一次Post两个文件,接收方就无法分割两个文件。
程序如下:
urlStr := 'http://10.0.1.12/dev//wfd/WFDServlet';
responseStream := TStringStream.Create('');
try
sourceStream := TMemoryStream.Create;
try
sourceStream.LoadFromFile(xmlFileName);
//HTTPClient是Indy的IdHTTP Client控件
HTTPClient.ProtocolVersion := pv1_1;
HTTPClient.Request.ContentType := 'multipart/form-data';
HTTPClient.Post(urlStr, sourceStream, responseStream);
finally
sourceStream.Free;
end;
if HTTPClient.ResponseCode = 200 then
begin
if Trim(responseStream.DataString) = '800 success' then
begin
ShowMsg('传输成功!');
end
else
begin
ShowMsg('传输失败!失败原因:' + Trim(responseStream.DataString));
end;
end
else
begin
ShowMsg('传输失败!失败原因:连接服务器失败!(' + HTTPClient.ResponseText + ')');
end;
finally
responseStream.Free;
end;
发现发送的时候没有boundary,即是以一个整体发过去的,与通过IE浏览器发送文件相比,
ContentType中少了boundary和其他的一些信息,发送的信息也没有像IE那样用boundary
分割开来,现在是发送一个文件,如果想一次Post两个文件,接收方就无法分割两个文件。
程序如下:
urlStr := 'http://10.0.1.12/dev//wfd/WFDServlet';
responseStream := TStringStream.Create('');
try
sourceStream := TMemoryStream.Create;
try
sourceStream.LoadFromFile(xmlFileName);
//HTTPClient是Indy的IdHTTP Client控件
HTTPClient.ProtocolVersion := pv1_1;
HTTPClient.Request.ContentType := 'multipart/form-data';
HTTPClient.Post(urlStr, sourceStream, responseStream);
finally
sourceStream.Free;
end;
if HTTPClient.ResponseCode = 200 then
begin
if Trim(responseStream.DataString) = '800 success' then
begin
ShowMsg('传输成功!');
end
else
begin
ShowMsg('传输失败!失败原因:' + Trim(responseStream.DataString));
end;
end
else
begin
ShowMsg('传输失败!失败原因:连接服务器失败!(' + HTTPClient.ResponseText + ')');
end;
finally
responseStream.Free;
end;