procedure TForm1.PostWeb;
const BaseURL = 'http://www.1798.cn'; //地址
//http://www.1798.cn/assistant/Login_Check.asp
var
IdHTTP: TIdHTTP;
Params: TStrings;
HTML: String;
begin
idHTTP:= TidHTTp.create(self);
Params := TStringList.Create;
IdHTTP.AllowCookies := True;
IdHTTP.HTTPOptions:=[hoForceEncodeParams];
IdHTTP.ProtocolVersion := pv1_1;
IDHTTP.Request.Accept:='*/*';
IdHTTP.Request.Referer:='http://www.1798.cn/assistant/login.asp?pageid=chengxin';
IdHTTP.Request.AcceptLanguage := 'zh-cn';
IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP.Request.AcceptEncoding := 'gzip, deflate';
IdHTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Alexa Toolbar; 56flvplayer 1.0)';
IdHTTP.Request.Host := 'http://www.1798.cn';
IdHTTP.Request.ContentLength := 8; // length('yong');
IdHTTP.Request.Connection := 'Keep-Alive';
IdHTTP.Request.CacheControl := 'no-cache';
Params.Add('UsernameGet='+'''+editname.text+''');
Params.Add('PasswordGet='+'''+editpd.text+'''); try
HTML:=IdHttp.Post(BaseURL+'/assistant/login.asp?pageid=chengxin',Params);
except
showmessage('error');
exit;
end; Edit1.Text := IdHttp.ResponseText;
IdHTTP.Disconnect;
FreeAndNil(IdHTTP);
FreeAndNil(Params);
end;
const BaseURL = 'http://www.1798.cn'; //地址
//http://www.1798.cn/assistant/Login_Check.asp
var
IdHTTP: TIdHTTP;
Params: TStrings;
HTML: String;
begin
idHTTP:= TidHTTp.create(self);
Params := TStringList.Create;
IdHTTP.AllowCookies := True;
IdHTTP.HTTPOptions:=[hoForceEncodeParams];
IdHTTP.ProtocolVersion := pv1_1;
IDHTTP.Request.Accept:='*/*';
IdHTTP.Request.Referer:='http://www.1798.cn/assistant/login.asp?pageid=chengxin';
IdHTTP.Request.AcceptLanguage := 'zh-cn';
IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP.Request.AcceptEncoding := 'gzip, deflate';
IdHTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Alexa Toolbar; 56flvplayer 1.0)';
IdHTTP.Request.Host := 'http://www.1798.cn';
IdHTTP.Request.ContentLength := 8; // length('yong');
IdHTTP.Request.Connection := 'Keep-Alive';
IdHTTP.Request.CacheControl := 'no-cache';
Params.Add('UsernameGet='+'''+editname.text+''');
Params.Add('PasswordGet='+'''+editpd.text+'''); try
HTML:=IdHttp.Post(BaseURL+'/assistant/login.asp?pageid=chengxin',Params);
except
showmessage('error');
exit;
end; Edit1.Text := IdHttp.ResponseText;
IdHTTP.Disconnect;
FreeAndNil(IdHTTP);
FreeAndNil(Params);
end;
MutPartForm: TIdMultiPartFormDataStream; MutPartForm.AddFormField('ssss','14');
MutPartForm.AddFormField('userName','test'); //
MutPartForm.AddFormField('file','同步');
MutPartForm.AddFormField('uploadFile',' ');
MutPartForm.AddFormField(submit1,submit1);
MutPartForm.AddFile('upfile',filename,''); Results := IdHTTP1.Post(URL2,MutPartForm);
这是我的一个上传的,参数用TIdMultiPartFormDataStream类型
就是不用在网页上输入登陆用户和密码就直接进入,输入数据由程序用POST的方式传达室递到登陆网页来完成。
idhttp.get('http://www.asdfasdf.com/login.asp?username=aaa&pwd=aaa')
dabaicai(一直是菜鸟) ,Get不行啊,我的这段代码好像有点问题,就是执行了以后它不能打开IE并输入用户名和密码进入主页,我也没有办法知道它是不是已经传递上去了,教教我啊!请各位大侠来帮忙啊!急啊,这个问题已经弄了一个星期了!
另外,post一般情况下我们用来上传下载文件,其他的操作我也没做过
var aST : String;
begin
aST := 'http://www.1798.cn/provide/search.asp?type=2&title=电子';
ShellExecute(0, 'open', pchar(aST), '', nil, 0); //打开指定网站
end;这个是我写好的,我点击以后呢就自动打开网页并把“电子”这个字符传给网页中的“title”变量,网页就自动搜索出“电子”相关的信息,但是我把这个方法用到需要输入用户名和密码登陆的页面上就不行了,网页能打开,但是用户名和密码的变量怎么都传不上去,在论坛上看了以后,像这样需要输入用户名和密码的页面要用Post的方式才能传递参数给网页里的用户名和密码变量,所以我就正在研究这个方法,不过我还没有研究出来,不懂Http的协议是怎么用的,请各位大侠帮忙想想办法!小弟在此多谢了!
同样登录里面不是用username和pwd这个参数传递,id="UsernameGet" ,id="PasswordGet" 难道你做东西都不看?????