我使用IdHttp post数据时.是要post一个memo组件的内容的.
这个memo里面的内容是:
111
222
333
然后.我post到一个页面.那么在这个页面显示的是111222333.
怎样才能让这个页面显示这样的结果?
111
222
333
当然.这个页面是没有问题的.它支持这个带格式的显示..
下面是我的代码.
procedure TForm1.Button3Click(Sender: TObject);
var
Url,s : string;
Response : TStringStream;
Request : TStrings;
begin
Response := TStringStream.Create('');
try
Request := TStringList.Create ;
try
s := 'logname=csz&password=123&mem='+Memo1.Text;
Request.Append(s);
Url:='Http://127.0.0.1/add.asp'
IdHTTP1.Request.ContentType :='application/x-www-form-urlencoded';
IdHTTP1.Post(Url,Request,Response);
Memo1.Lines.Text := Trim(Response.DataString);
finally
Request.Free ;
end;
finally
Response.Free ;
end;
end;
这个memo里面的内容是:
111
222
333
然后.我post到一个页面.那么在这个页面显示的是111222333.
怎样才能让这个页面显示这样的结果?
111
222
333
当然.这个页面是没有问题的.它支持这个带格式的显示..
下面是我的代码.
procedure TForm1.Button3Click(Sender: TObject);
var
Url,s : string;
Response : TStringStream;
Request : TStrings;
begin
Response := TStringStream.Create('');
try
Request := TStringList.Create ;
try
s := 'logname=csz&password=123&mem='+Memo1.Text;
Request.Append(s);
Url:='Http://127.0.0.1/add.asp'
IdHTTP1.Request.ContentType :='application/x-www-form-urlencoded';
IdHTTP1.Post(Url,Request,Response);
Memo1.Lines.Text := Trim(Response.DataString);
finally
Request.Free ;
end;
finally
Response.Free ;
end;
end;
var
data: TIdMultiPartFormDataStream;
begin
data := TIdMultiPartFormDataStream.Create;
try
{ add the used parameters for the script }
data.AddFormField('param1', 'value1');
data.AddFormField('param2', 'value2');
data.AddFormField('param3', 'value3'); { Call the Post method of TIdHTTP and read the result into TMemo }
Memo1.Lines.Text := IdHTTP1.Post('http://localhost/script.php', data);
finally
data.Free;
end;
end;
var
Url,s : string;
Response : TStringStream;
Request : TStrings;
begin
Response := TStringStream.Create('');
try
Request := TStringList.Create ;
try
s := 'logname=csz&password=123&mem='+Memo1.Text;
Request.Append(s);
Url:='Http://127.0.0.1/add.asp'
IdHTTP1.Request.ContentType :='application/x-www-form-urlencoded';
IdHTTP1.Post(Url,Request,Response);
Memo1.Lines.add(Trim(Response.DataString));
finally
Request.Free ;
end;
finally
Response.Free ;
end;
end;
IdHTTP1.Post(Url,Request,Response);
这个Response.DataString就是存储了返回的数据.继续顶..
我已经试了很多的网站.提交的都是不带格式的.都是提交成了一行(不分行.不带格式).
以前是解决了这个问题.是idhttp组件的事.但现在忘记怎么处理的了..
procedure TForm1.Button3Click(Sender: TObject);
var
Url,s : string;
Response : TStringStream;
Request : TStrings;
I: Integer;
begin
Response := TStringStream.Create('');
try
Request := TStringList.Create ;
try
s := 'logname=csz&password=123&mem='+Memo1.Text;
for I := 0 to Memo1.lines.Count - 1 do
begin
S := S + Memo1.Lines[I] + '<br>'; //
end;
Request.Append(s);
Url:='Http://127.0.0.1/add.asp'
IdHTTP1.Request.ContentType :='application/x-www-form-urlencoded';
IdHTTP1.Post(Url,Request,Response);
Memo1.Lines.Text := Trim(Response.DataString);
finally
Request.Free ;
end;
finally
Response.Free ;
end;
end;
#13='<br>'
' '='%20'
这样.通过idhttp的编码.web页面就可以显示正常带简单格式的文本了.