Delphi XE中的POST请求 [英] POST request in Delphi XE

查看:161
本文介绍了Delphi XE中的POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要任务是通过Delphi程序进行开机自检.使用REST客户端,我发现具有站点的网址和两个标头:* login_email *和* login_pass *我可以成功获取HTML密码,并且我的POST身份验证表单还可以,我已经登录.

Main task is POST-autorization via Delphi program. Using the REST Client I found that, having url of site and two headers: *login_email* and *login_pass* I can successfully get the HTML codу and my POST auth form is OK, I'm logged in.

但是,我编写了以下Delphi代码:

However, I wrote this Delphi code:

DataToSend := TStringList.Create;
DataToSend.Add('');

IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP1.Request.CustomHeaders.AddValue('login_email','some_email');
IdHTTP1.Request.CustomHeaders.AddValue('login_pass','some_password');

Memo1.Lines.Add(idHTTP1.Post('http://url.com', DataToSend));

我的自定义标头未进行URL编码.

My custom headers are not URL encoded.

我看到了请求标头:

Server: nginx/1.0.8
Date: Sun, 01 Sep 2013 17:03:59 GMT
Content-Type: text/html; charset=windows-1251
Connection: close
X-Powered-By: PHP/5.2.6-1+lenny16
Vary: Accept-Encoding

但是保留的HTML是同一页面,已以未经处理的形式发送了POST请求.

but ontained HTML is same page, for which POST-request has been sent with unprocessed form.

我在做什么错了?

推荐答案

POST请求参数从不包含在HTTP标头中.尝试:

The POST request parameters never includes in HTTP header. Try that:

DataToSend := TStringList.Create;
DataToSend.Add('login_email=some_email');
DataToSend.Add('login_pass=some_password');
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';

Memo1.Lines.Add(idHTTP1.Post('http://url.com', DataToSend));

这篇关于Delphi XE中的POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆