这是一长城宽带的认证页面,每当20分钟没有数据传输后,就会自动断掉网络连接,要想重新上网,就得进入认证页面,输入用户名和密码,然后单击“认证”(这里是一张图片,方法为POST),通过后才能继续上网。
这是认证页面的关键代码:
<table width="100%" border="0" cellpadding="4" cellspacing="0" bgcolor="#999999">
          <form name=authenticateForm action=http://211.162.130.24:9091/user/home?textfield2=&amp;textfield=&amp;image.y=17&amp;image.x=10&amp;t=dag191op method=post>
            <tr> 
              <td width="94" align="center" valign="middle"><img src="new_images/rrrr.jpg" width="80" height="19"></td>
              <td width="296" valign="middle"><span class="p1"><font color="#FFFFFF"><font color="#000000">帐 
                号:</font></font></span> <input name="username" type="text" class="qqqqqqqq" size="10"> 
                <span class="p1"><font color="#FFFFFF">  <font color="#000000">密 
                码:</font></font></span><font color="#FFFFFF"> 
                <input name="password" type="password" class="qqqqqqqq" size="10">
                </font></td>
              <td width="61" valign="middle"><font color="#FFFFFF"><input name="image4" type="image" onclick=return src="images/dl.jpg" width="41" height="15" loginin(this);> <span class="p1"></span></font></td>
          </form>
        </table>
我想写个程序,当网络连接被断开后,自动发送用户名和密码通过认证,请高手给个思路,有源码更好,分不够可以再开新贴给,绝不食言!

解决方案 »

  1.   

    ...automatic fill out HTML forms with TWebBrowser?  
    Autor: Simon Grossenbacher  
    Homepage: http://www.swissdelphicenter.ch 
    2 Comment(s) to this tip [Write new comment] 
    [ Print tip ]     Tip Rating (14):   
          
    { To test this code put a TWebBrowser and A TButton component on the form } 
    function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;  
    var  
      i, j: Integer;  
      FormItem: Variant;  
    begin  
      Result := False;  
      //no form on document  
      if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then  
      begin  
        Exit;  
      end;  
      //count forms on document  
      for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do  
      begin  
        FormItem := WebBrowser.OleObject.Document.forms.Item(I);  
        for j := 0 to FormItem.Length - 1 do  
        begin  
          try  
            //when the fieldname is found, try to fill out  
            if FormItem.Item(j).Name = FieldName then  
            begin  
              FormItem.Item(j).Value := Value;  
              Result := True;  
            end;  
          except  
            Exit;  
          end;  
        end;  
      end;  
    end;  
    //When the document is complete try to fill out the field homepage with the url  
    procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;  
      const pDisp: IDispatch; var URL: OleVariant);  
    begin  
      if FillForm(WebBrowser1, 'homepage', 'http://www.swissdelphicenter.ch') = False then  
        ShowMessage('Error. Field not available or no Form found.'); 
    end; // Show the Webbrowser-Progress in Label1  
    procedure TForm1.WebBrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer);  
    begin  
      if ProgressMax = 0 then  
      begin  
        label1.Caption := '';  
        Exit;  
      end;  
      try  
        if (Progress <> -1) and (Progress <= ProgressMax) then  
          label1.Caption := IntToStr((Progress * 100) div ProgressMax) + '% loaded...'  
        else  
          label1.Caption := '';  
      except  
        on EDivByZero do Exit;  
      end;  
    end;  
    //For example you can load the page /en/addtip.php to the TWebBrowser  
    //When the document is Complete the form where you can put your homepage  
    //address is filled out  
    procedure TForm1.Button1Click(Sender: TObject);  
    begin  
      Webbrowser1.Navigate('http://www.swissdelphicenter.ch/en/addtip.php');  
      // Show the Titel of the currently active Webpage in the titlebar  
      // Den Titel der aktuellen Webseite in der Titeleiste anzeigen  
      Caption := Webbrowser1.OleObject.Document.Title;  
    end; 
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      postList: TStrings;
    begin
      EditURL.Text := 'http://211.162.130.24:9091/user/home?t=dwg2zn63';  postList := TStringList.Create;
      try
        postList.Add('username=yourName');
        postList.Add('password=yourPassword');
        IdHTTP.Post( EditURL.Text, postList );
      finally
        EditURL.Text := IdHTTP.Response.Server + ': ' + IdHTTP.Response.ResponseText;
        postList.Free;
      end;
    end;(注:用TIdHTTP控件、试试这样能叫通吗?)
      

  3.   

    cronuz,你写的代码运行过没?执行到idhttp.post就停止响应了,我对这个控件不熟,是不是忘了设置某些属性?
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      postList: TStrings;
    begin
      EditURL.Text := 'http://community.csdn.net/expert/forum.asp';  postList := TStringList.Create;
      try
        postList.Add('login_name=cronuz');
        postList.Add('password=myPassword');
        IdHTTP.Post( EditURL.Text, postList );
      finally
        EditURL.Text := IdHTTP.Response.Server + ': ' + IdHTTP.Response.ResponseText;
        postList.Free;
      end;
    end;(注:此為在CSDN上的TEST、楼主只要改成自己在CSDN上的用户名和密码、
       就可叫通CSDN、返回:Microsoft-IIS/6.0: HTTP/1.1 200 OK)