delphi 写了一个ocx文件,
idhttp.post(url,inStream,reStream)发送数据, 发送的数据是文件。
JSP端应该如何接收发送来的数据
DELPHI 代码如下。
var
Source: TMemoryStream;
Source1: TMemoryStream;
Response: TStringStream;
S,s1: String;
begin
Screen.Cursor := crHourGlass;
IdAntiFreeze1.OnlyWhenIdle:=False;//设置使程序有反应.
try HTTP.Request.Username := '';
HTTP.Request.Password := '';
HTTP.Port := 80;
HTTP.Request.ContentType := 'multipart/form-data';
Response := TStringStream.Create('');
try S := '-----------------------------7cf1d6c47c' + CRLF +
'Content-Disposition: form-data; name="file1"; filename="'+FileName+'"'+CRLF +
'Content-Type: application/octet-stream' + CRLF + CRLF; //上传文件内容
s1:='file one content. Contant-Type can be application/octet-stream or if'+
'you want you can ask your OS fot the exact type.' + CRLF +
'-----------------------------7cf1d6c47c' + CRLF + //分界符,用于分隔表单(Form)中的各个域
'Content-Disposition: form-data; name="text1"' + CRLF + CRLF +
'hello2' + CRLF +
'-----------------------------7cf1d6c47c--'; //提交的下一个表单内容域的内容
s1:=CRLF +'-----------------------------7cf1d6c47c' + CRLF +
'Content-Disposition: form-data; name="text1"' + CRLF + CRLF +
'hello2' + CRLF +
'-----------------------------7cf1d6c47c--'; Source := TMemoryStream.Create;
Source1 := TMemoryStream.Create;
Source1.LoadFromFile(FileName);
Response:=TStringStream.Create('') ;
Response.CopyFrom(source1,source1.Size); s:=s+Response.DataString;
Source.Position :=0;
Source.Write(s[1],length(s));
Source.Position :=source.Size ;
Source.Write(s1[1],length(s1));
Response.Position :=0;
try
HTTP.Post(URL, Source, Response);
if pos('成功',response.datastring)<>0 then
Result := True
else
begin
Result := True
end;
except
Result := False;
end;
Source.Free;
finally
Response.Free;
end;
finally
Screen.Cursor := crDefault;
end;
end;
idhttp.post(url,inStream,reStream)发送数据, 发送的数据是文件。
JSP端应该如何接收发送来的数据
DELPHI 代码如下。
var
Source: TMemoryStream;
Source1: TMemoryStream;
Response: TStringStream;
S,s1: String;
begin
Screen.Cursor := crHourGlass;
IdAntiFreeze1.OnlyWhenIdle:=False;//设置使程序有反应.
try HTTP.Request.Username := '';
HTTP.Request.Password := '';
HTTP.Port := 80;
HTTP.Request.ContentType := 'multipart/form-data';
Response := TStringStream.Create('');
try S := '-----------------------------7cf1d6c47c' + CRLF +
'Content-Disposition: form-data; name="file1"; filename="'+FileName+'"'+CRLF +
'Content-Type: application/octet-stream' + CRLF + CRLF; //上传文件内容
s1:='file one content. Contant-Type can be application/octet-stream or if'+
'you want you can ask your OS fot the exact type.' + CRLF +
'-----------------------------7cf1d6c47c' + CRLF + //分界符,用于分隔表单(Form)中的各个域
'Content-Disposition: form-data; name="text1"' + CRLF + CRLF +
'hello2' + CRLF +
'-----------------------------7cf1d6c47c--'; //提交的下一个表单内容域的内容
s1:=CRLF +'-----------------------------7cf1d6c47c' + CRLF +
'Content-Disposition: form-data; name="text1"' + CRLF + CRLF +
'hello2' + CRLF +
'-----------------------------7cf1d6c47c--'; Source := TMemoryStream.Create;
Source1 := TMemoryStream.Create;
Source1.LoadFromFile(FileName);
Response:=TStringStream.Create('') ;
Response.CopyFrom(source1,source1.Size); s:=s+Response.DataString;
Source.Position :=0;
Source.Write(s[1],length(s));
Source.Position :=source.Size ;
Source.Write(s1[1],length(s1));
Response.Position :=0;
try
HTTP.Post(URL, Source, Response);
if pos('成功',response.datastring)<>0 then
Result := True
else
begin
Result := True
end;
except
Result := False;
end;
Source.Free;
finally
Response.Free;
end;
finally
Screen.Cursor := crDefault;
end;
end;
解决方案 »
- case语句的用法
- Delphi5.0调用存储过程
- delphi中有计算矩阵的函数(比如求逆矩阵)和求指数的函数吗?
- Tstream中的Read()和ReadBuff()的区别
- 一个简单的 String语句如何实现!
- 懇請CSDN版面負責人重視﹐我們期待自己能回來
- 用nmftp控件实现文件下载的过程中,连接连接被abort掉,但是传输并没有中断,只是不能下载文件了,如何实现再次连接并下载文件啊,帮帮忙啊
- 如何动态选定数据库字段名后,实现动态生成打印报表.
- 可怜,quickReport怎样才能用到Win2000上?
- 运行时如何接收文件打开命令!
- Delphi错误编号解释 顶者有分
- TObjectList 有20万条;如何快速 填充到 Stringlist 上面
代码类似private byte[] recvFile(){
StringBuilder sb = new StringBuilder();
try{
BufferedReader br = request.getReader();
String len=null;
while((len=br.readLine())!=null){
sb.append(len);
}
byte[] b = sb.toString().getBytes();
return b;
}
catch(Exception ex){
return null;
}
}