全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2057
推到 Plurk!
推到 Facebook!

idHTTP

尚未結案
cjbo
一般會員


發表:4
回覆:4
積分:1
註冊:2003-04-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-02 23:39:33 IP:211.163.xxx.xxx 未訂閱
请问用IDHTTP可以把文件上传到WEB站点吗? 用PUT还是POST? 其中参数应该怎样设? 放棄留戀著的快樂, 也就是擺脫了痛苦.
------
放棄留戀著的快樂,
也就是擺脫了痛苦.
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-04 00:16:41 IP:61.225.xxx.xxx 未訂閱
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-05 13:36:40 IP:218.14.xxx.xxx 未訂閱
引言: 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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-05-07 17:12:11 IP:61.216.xxx.xxx 未訂閱
另一範例:    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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-04-26 13:52:45 IP:000.000.xxx.xxx 未訂閱
提問者您好:


以上回應是否已得到滿意的答覆?


若已得到滿意的答覆,請在一週內結案,否則請在一週內回覆還有什麼未盡事宜,不然,
將由版主(尚無版主之區域將由副站長或站長)自由心證,選擇較合適之解答予以結案處理,
被選上之答題者同樣會有加分獎勵同時發問者將受到扣 1 分的處分。不便之處,請見諒。


有問有答有結案,才能有良性的互動,良好的討論環境需要大家共同維護,感謝您的配合。

------
我是機器人,我不接受簡訊.
系統時間:2024-04-26 12:46:56
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!