我想使用Delphi连接到嵌入式网页。如何使用TIdHTTP
登录该网页?我尝试了这段代码,但它没有保持连接。标准POST操作不包含在页面中。您看到该页面不包含表单。我该怎么做呢?这个页面需要什么POST?
这是我的代码:
IdHTTP1.Get('http://192.168.1.139/chklogin.php?a=0&u=admin&p=123456',ms);
IdHTTP1.Connect;
ShowMessage(IdHTTP1.ResponseText);
我试过这种方式;
PostData := TStringList.Create;
PostData.Add('u='+user);
PostData.Add('pw='+password);
PostData.Add('submit=??????? ); // <-- What goes here?
IdHTTP1.Post('192.168.1.39/login', PostData);
[
function submit(){
var pwd=$get('pw');
var uname=$get('u');
msgd=$get('msg');
msgd.innerHTML='';
if (uname.value.length===0){
inpB=uname;
dm("Enter Your Username");
return;
}else if (pwd.value.length===0){
inpB=pwd;
dm("Enter Your Password");
return;
}else{
xmlhttpLog=$createXMLHttp();
inpB=msgd;
inpB.style.border="1px solid red";
dm("Checking with TPL-Net");
xmlhttpLog.open('GET', '/chklogin.php?a=0&u='+uname.value+'&p='+pwd.value+'&d='+$stamp(),false);
xmlhttpLog.send(null);
fileContent=xmlhttpLog.responseText;
if (fileContent=='E'){
dm("Wrong Username/Password");
uname.value='';
pwd.value='';
}else{
setCookie('tplnet',fileContent);
dm('Granted. Redirecting...<br>If redirection doesn\'t work click <a href="/index.html">here</a>');
setTimeout("window.location='/index.html';",2000);
}
}
}
</script>
<td>User Name:</td>
<td><input id="u" type="text" name="uname" style="width: 150px;"/></td>
</tr><tr>
<td>Password:</td>
<td><input id="pw" type="password" name="pwd" style="width: 150px;" /></td>
</tr><tr>
<td height="50px" colspan="2"><a style="margin-top:20px;" class="buton" href="#" onClick="submit();">
<span>Login</span></a>
</td>
]
不要手动调用Connect()
! Get()
为您内部处理。
Get()
的返回值包含响应内容,ResponseText
不是你想要的。
试试这个:
ShowMessage(IdHTTP1.Get('http://192.168.1.139/chklogin.php?a=0&u=admin&p=123456');