在HTML文件表单提交产生的HTTP请求是什么样子的(30分)

  • 主题发起人 主题发起人 sunjunfeng3
  • 开始时间 开始时间
S

sunjunfeng3

Unregistered / Unconfirmed
GUEST, unregistred user!
我想知道在HTML文件中的表单提交时产生的HTTP请求是什么样子的
我想在程序中构建这个HTTP请求,通过idHTTP控件把程序中的数据用这种HTTP请求递交到ASP文件上进行处理,
也就是说,在DELPHI程序中自动把数据提交到网上去,我只想知道这个HTTP请求是什么样的,

各位大吓可不可以积急点回答我的问题这是我最后30分送上了,如果不会就请转告,一下高手我在线等
 
google上找的,试了几个网站,有的网站不成功。

Using Indy idHTTP to post binary and text
Note: Click Title to view in Edit Box for easier copying.

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' + '&amp;'))

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&amp;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.

Doychin - Team Indy
doychin@dsoft-bg.com
WebPage: http://www.nevrona.com/indy/
 
编译时找URLEncode()没有找到,不能识别
 
忘了,
uses idGlobal;
 
后退
顶部