procedure TForm1.SendFile(filename: string);
var
Source: TMemoryStream ;
Response: TStringStream;
workPostContentstream : TStringStream ;
filestream: TMemorystream;
tep: string;
const
crLf = #$D#$A;
Sectboundary = '-----------------------------7d374371d050e';
begin
if FileExists(filename) then
begin
Response := TStringStream.Create('');
Source := TMemoryStream.Create;
workPostContentstream := TStringStream.Create('');
source.LoadFromFile(filename);
IDHTTP1.ProtocolVersion := pv1_1 ;
try
workPostContentstream.WriteString(Sectboundary); //分隔符
workPostContentstream.WriteString(crLf); // 换行
workPostContentstream.WriteString(format('Content-Disposition: form-data; name="%s" ',['id'])); //输入upload file的form name 和 filename
workPostContentstream.WriteString(crLf);
workPostContentstream.WriteString(crLf);
workPostContentstream.WriteString(FUserID);
workPostContentstream.WriteString(crLf);
workPostContentstream.WriteString(Sectboundary); //分隔符
workPostContentstream.WriteString(crLf); // 换行
workPostContentstream.WriteString(format('Content-Disposition: form-data; name="%s" ; filename="%s"',['file', filename])); //输入upload file的form name 和 filename
workPostContentstream.WriteString(crLf);
workPostContentstream.WriteString('Content-Type: audio/wav');
workPostContentstream.WriteString(crLf); // 换行
workPostContentstream.WriteString(crLf); // 换行
workPostContentstream.CopyFrom(source, source.Size);
workPostContentstream.WriteString(crLf); // 换行
workPostContentstream.WriteString(Sectboundary); //分隔符
workPostContentstream.WriteString(crLf); // 换行
IDHTTP1.Post(FURL, workPostContentstream, Response);
tep := Response.DataString;
if pos('ok',tep) >0
then
begin
Application.MessageBox('您的像片已成功上传!','',MB_OK);
//CloseIE;
end
else
begin
if sendcount < 3 then
begin
sendcount := sendcount + 1;
SendWavFile(filename);
end
else
begin
StatusBar1.Panels.Items[0].Text := '像片上传失败';
end ;
end;
except
Application.MessageBox('网络连接错误,传送失败!','错误',MB_ICONERROR+MB_OK);
workPostContentstream.Free;
Response.Free;
source.Free;
exit;
end;
workPostContentstream.Free;
Response.Free;
source.Free;
end;
end;
[
][
]