idHTTP |
尚未結案
|
cjbo
一般會員 發表:4 回覆:4 積分:1 註冊:2003-04-15 發送簡訊給我 |
|
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
unit Main; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP; type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
http: TIdHTTP;
cbURL: TEdit;
PostData: TMemo;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end; procedure TForm1.Button1Click(Sender: TObject);
var
Response : TStringStream;
// PostData : string;
begin
Response := TSTringStream.Create('');
cbURL.Text := 'http://esales.mir2.com.cn/chklogin_test.asp';
Http.Post(cbURL.Text,PostData.Lines,Response);
Memo1.Text := Response.DataString;
Response.Free;
end; end. 發表是最好的記憶! 發表人 - qoo1234 於 2003/05/04 00:51:42
|
cjbo
一般會員 發表:4 回覆:4 積分:1 註冊:2003-04-15 發送簡訊給我 |
引言: unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, OleCtrls, SHDocVw, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP; type TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit; Label2: TLabel; Edit2: TEdit; Button1: TButton; Button2: TButton; Memo1: TMemo; http: TIdHTTP; cbURL: TEdit; PostData: TMemo; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button2Click(Sender: TObject); begin Close; end; procedure TForm1.Button1Click(Sender: TObject); var Response : TStringStream; // PostData : string; begin Response := TSTringStream.Create(''); cbURL.Text := 'http://esales.mir2.com.cn/chklogin_test.asp'; Http.Post(cbURL.Text,PostData.Lines,Response); Memo1.Text := Response.DataString; Response.Free; end; end. 發表是最好的記憶! 發表人 - qoo1234 於 2003/05/04 00:51:42請問為什麽會有錯誤信息:HTTP/1.1 302 NOT FOUND 放棄留戀著的快樂, 也就是擺脫了痛苦.
------
放棄留戀著的快樂, 也就是擺脫了痛苦. |
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
另一範例: Using Indy idHTTP to post binary and text This is a small example of using post to send data to web server. There is two different ways to do this operation. Example 1:
<----------------------------------------------------------------->
procedure TForm1.SendPostData;
Const
CRLF = #13#10;
Var
aStream: TMemoryStream;
Params: TMemoryStream;
S: String;
begin
aStream := TMemoryStream.create;
Params := TMemoryStream.Create; HTTP.Request.ContentType := 'multipart/form-data;
boundary=-----------------------------7cf87224d2020a'; try
S := '-----------------------------7cf87224d2020a' + CRLF +
'Content-Disposition: form-data; name="file1"; filename="c:abc.txt"' +
CRLF +
'Content-Type: text/plain' + CRLF + CRLF +
'file one content. Contant-Type can be application/octet-stream or if
you want you can ask your OS fot the exact type.' + CRLF +
'-----------------------------7cf87224d2020a' + CRLF +
'Content-Disposition: form-data; name="sys_return_url2"' + CRLF + CRLF +
'hello2' + CRLF +
'-----------------------------7cf87224d2020a--'; Params.Write(S[1], Length(S)); with HTTP do begin
try
HTTP.Post('http://www.mydomain.com/postexampe.cgi', Params,
aStream);
except
on E: Exception do
showmessage('Error encountered during POST: ' + E.Message);
end;
end;
aStream.WriteBuffer(#0' ', 1);
showmessage(PChar(aStream.Memory));
except
end;
end;
<-----------------------------------------------------------------> Example 2:
<----------------------------------------------------------------->
procedure TForm1.SendPostData;
Var
aStream: TMemoryStream;
Params: TStringStream;
begin
aStream := TMemoryStream.create;
Params := TStringStream.create('');
HTTP.Request.ContentType := 'application/x-www-form-urlencoded'; try
Params.WriteString(URLEncode('sys_return_url=' + 'helo1' + '&'));
Params.WriteString(URLEncode('sys_return_url=' + 'helo2'));
with HTTP do begin
try
HTTP.Post('http://www.mydomain.com/postexampe.cgi', Params,
aStream);
except
on E: Exception do
showmessage('Error encountered during POST: ' + E.Message);
end;
end;
aStream.WriteBuffer(#0' ', 1);
showmessage(PChar(aStream.Memory));
except
end;
end;
<-----------------------------------------------------------------> As you can see there is a difference in the way post stream is constructed
and the ContentType. In the first example ContentType is
"multipart/form-data; boundary=-----------------------------7cf87224d2020a"
and this boundary is used to separate different parameters. In the second example the ContentType is
"application/x-www-form-urlencoded".
In this case the paremeteras are passed in the form ParamName=ParamValue&ParamName=ParamValue Note that the Pramaeters in the second form must be URL encoded. Where these two formats of post information are used? The first one is used when you have binary data to post and the second one
is when you are going to post only text fields. 發表是最好的記憶!
|
Ktop_Robot
站務副站長 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |