1 | unit Unit1;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
7 | HTTPSend, StdCtrls, ExtCtrls;
|
---|
8 |
|
---|
9 | type
|
---|
10 | TForm1 = class(TForm)
|
---|
11 | Panel1: TPanel;
|
---|
12 | Panel2: TPanel;
|
---|
13 | Panel3: TPanel;
|
---|
14 | Panel4: TPanel;
|
---|
15 | Memo1: TMemo;
|
---|
16 | Memo2: TMemo;
|
---|
17 | Label1: TLabel;
|
---|
18 | Edit1: TEdit;
|
---|
19 | Button1: TButton;
|
---|
20 | Label2: TLabel;
|
---|
21 | Label3: TLabel;
|
---|
22 | Edit2: TEdit;
|
---|
23 | Button2: TButton;
|
---|
24 | Label4: TLabel;
|
---|
25 | Label5: TLabel;
|
---|
26 | Edit3: TEdit;
|
---|
27 | Label6: TLabel;
|
---|
28 | Edit4: TEdit;
|
---|
29 | Label7: TLabel;
|
---|
30 | Label8: TLabel;
|
---|
31 | Edit5: TEdit;
|
---|
32 | Button3: TButton;
|
---|
33 | Label9: TLabel;
|
---|
34 | Edit6: TEdit;
|
---|
35 | Edit7: TEdit;
|
---|
36 | Label10: TLabel;
|
---|
37 | Panel5: TPanel;
|
---|
38 | Label11: TLabel;
|
---|
39 | Label12: TLabel;
|
---|
40 | Edit8: TEdit;
|
---|
41 | Edit9: TEdit;
|
---|
42 | Label13: TLabel;
|
---|
43 | procedure Button1Click(Sender: TObject);
|
---|
44 | procedure Button2Click(Sender: TObject);
|
---|
45 | procedure Button3Click(Sender: TObject);
|
---|
46 | private
|
---|
47 | { Private declarations }
|
---|
48 | public
|
---|
49 | { Public declarations }
|
---|
50 | end;
|
---|
51 |
|
---|
52 | var
|
---|
53 | Form1: TForm1;
|
---|
54 |
|
---|
55 | implementation
|
---|
56 |
|
---|
57 | {$R *.DFM}
|
---|
58 |
|
---|
59 | function ProxyHttpPostURL(const URL, URLData: string; const Data: TStream): Boolean;
|
---|
60 | var
|
---|
61 | HTTP: THTTPSend;
|
---|
62 | begin
|
---|
63 | HTTP := THTTPSend.Create;
|
---|
64 | try
|
---|
65 | HTTP.ProxyHost := Form1.Edit8.Text;
|
---|
66 | HTTP.ProxyPort := Form1.Edit9.Text;
|
---|
67 | HTTP.Document.Write(Pointer(URLData)^, Length(URLData));
|
---|
68 | HTTP.MimeType := 'application/x-www-form-urlencoded';
|
---|
69 | Result := HTTP.HTTPMethod('POST', URL);
|
---|
70 | Data.CopyFrom(HTTP.Document, 0);
|
---|
71 | finally
|
---|
72 | HTTP.Free;
|
---|
73 | end;
|
---|
74 | end;
|
---|
75 |
|
---|
76 | function ProxyHttpPostFile(const URL, FieldName, FileName: string;
|
---|
77 | const Data: TStream; const ResultData: TStrings): Boolean;
|
---|
78 | const
|
---|
79 | CRLF = #$0D + #$0A;
|
---|
80 | var
|
---|
81 | HTTP: THTTPSend;
|
---|
82 | Bound, s: string;
|
---|
83 | begin
|
---|
84 | Bound := IntToHex(Random(MaxInt), 8) + '_Synapse_boundary';
|
---|
85 | HTTP := THTTPSend.Create;
|
---|
86 | try
|
---|
87 | HTTP.ProxyHost := Form1.Edit8.Text;
|
---|
88 | HTTP.ProxyPort := Form1.Edit9.Text;
|
---|
89 | s := '--' + Bound + CRLF;
|
---|
90 | s := s + 'content-disposition: form-data; name="' + FieldName + '";';
|
---|
91 | s := s + ' filename="' + FileName +'"' + CRLF;
|
---|
92 | s := s + 'Content-Type: Application/octet-string' + CRLF + CRLF;
|
---|
93 | HTTP.Document.Write(Pointer(s)^, Length(s));
|
---|
94 | HTTP.Document.CopyFrom(Data, 0);
|
---|
95 | s := CRLF + '--' + Bound + '--' + CRLF;
|
---|
96 | HTTP.Document.Write(Pointer(s)^, Length(s));
|
---|
97 | HTTP.MimeType := 'multipart/form-data, boundary=' + Bound;
|
---|
98 | Result := HTTP.HTTPMethod('POST', URL);
|
---|
99 | ResultData.LoadFromStream(HTTP.Document);
|
---|
100 | finally
|
---|
101 | HTTP.Free;
|
---|
102 | end;
|
---|
103 | end;
|
---|
104 |
|
---|
105 |
|
---|
106 | procedure TForm1.Button1Click(Sender: TObject);
|
---|
107 | var
|
---|
108 | HTTP: THTTPSend;
|
---|
109 | begin
|
---|
110 | HTTP := THTTPSend.Create;
|
---|
111 | try
|
---|
112 | HTTP.ProxyHost := Edit8.Text;
|
---|
113 | HTTP.ProxyPort := Edit9.Text;
|
---|
114 | HTTP.HTTPMethod('GET', Edit1.text);
|
---|
115 | Memo1.Lines.Assign(HTTP.Headers);
|
---|
116 | Memo2.Lines.LoadFromStream(HTTP.Document);
|
---|
117 | finally
|
---|
118 | HTTP.Free;
|
---|
119 | end;
|
---|
120 | end;
|
---|
121 |
|
---|
122 | procedure TForm1.Button2Click(Sender: TObject);
|
---|
123 | var
|
---|
124 | st: TMemoryStream;
|
---|
125 | begin
|
---|
126 | st:=TMemoryStream.Create;
|
---|
127 | try
|
---|
128 | ProxyHTTPpostURL(Edit2.Text, Edit3.Text + '=' + Edit4.Text, st);
|
---|
129 | st.Seek(0,soFromBeginning);
|
---|
130 | Memo2.Lines.LoadFromStream(st);
|
---|
131 | finally
|
---|
132 | st.Free;
|
---|
133 | end;
|
---|
134 | end;
|
---|
135 |
|
---|
136 | procedure TForm1.Button3Click(Sender: TObject);
|
---|
137 | var
|
---|
138 | st: TFileStream;
|
---|
139 | begin
|
---|
140 | st := TFileStream.Create(Edit7.Text, fmOpenRead or fmShareDenyWrite);
|
---|
141 | try
|
---|
142 | ProxyHTTPPostFile(Edit5.Text, Edit6.Text, ExtractFilename(Edit7.Text), st, TStringList(memo2.Lines));
|
---|
143 | finally
|
---|
144 | st.Free;
|
---|
145 | end;
|
---|
146 | end;
|
---|
147 |
|
---|
148 | end.
|
---|