我想用程序實現更新動態域名的過程,我是在3322.org申請的服務,在其網站有相關協議如下:
http://www.3322.org/dyndnspage/protocol.html
Client的请求应该使用HTTP/1.0以上协议,Server的相应一定为HTTP/1.0支持HTTP和基于SSL的HTTPS协议需要事务处理,Client发送完整的请求,并且解析服务器端的相应,保证域名更新的成功1. 通过URL认证 (所有的在一行)
http://username:[email protected]/dyndns/update?system=dyndns&hostname=yourhost.ourdomain.ext&myip=ipaddress&wildcard=OFF
&mx=mail.exchanger.ext&backmx=NO&offline=NO
.....
..........
我用idhttp控件在button.click事件中寫入
 try
   IdHTTP1.Get('http://myaccount:[email protected]/dyndns/update?system=dyndns&hostname=yourhost.ourdomain.ext&61.129.47.77=ipaddress&wildcard=OFF');
     except
     case IdHTTP1.ResponseCode of
     401 : ShowMessage('wrong name and pass');
     -1 :  ShowMessage('url not exist');
     end;
     ShowMessage(IntToStr(IdHTTP1.ResponseCode));
   end;
但總是showmessage('0');請問我該怎麼做才對?我對此是一窍不通,以上代碼也是網上找來的,請大家說的詳細些,謝謝.

解决方案 »

  1.   

    看样子,是你设的idhttp1的属性不对导致的,我新加了个idhttp1,然后把你的代码复制进去,执行后,显示'wrong name and pass和401
      

  2.   

    即使这段代码能够显示出200来,也是不能如你所愿来完成你的后续功能的。
    因为,它使用了session来记录用户登录状态,idhttp本身是不记录session的,需要通过一些技术手段来伪造session。提前给你一段代码,你一定会用上的哈。以Get为例,idhttp伪造session
            IdHttp1.Get(mURL1);
            mStr := IdHttp1.Response.CustomHeaders.Values['Set-Cookie'];
            if Pos(';',mStr)>0 then
                    Session_ID := LeftBStr(mStr,Pos(';',mStr)-1)
            else
                    Session_ID := mStr;        IdHttp1.Request.CustomHeaders.Add('Cookie:' + Session_ID);
            IdHttp1.Get(mURL2);
      

  3.   

    我沒有改過idhttp的屬性呀?整個程序只有idhttp和一button,新建一project後加入以上兩控件後執行還是一樣showmessage('0'),我用的是delphi 6.
    請問mURL1是否登錄網頁的地址?如www.3322.org
    mURL2是否http://myaccount:[email protected]/dyndns/update?system=dyndns&hostname=yourhost.ourdomain.ext&61.129.47.77=ipaddress&wildcard=OFF
      

  4.   

    mURL1应该是你后面的那个URL,访问那个连接服务器会返回session数据,只有以后的访问,客户端都带上这个session数据,服务器才会认为这是个经过验证的访问(用户名及密码相符),mURL2就是登录以后,你想继续访问的连接。
      

  5.   

    try
        IdHTTP1.Get('http://myaccount:[email protected]/dyndns/update?system=dyndns&hostname=yourhost.ourdomain.ext&61.129.47.77=ipaddress&wildcard=OFF');
        case IdHTTP1.ResponseCode of
          401: ShowMessage('wrong name and pass');
          -1: ShowMessage('url not exist');
        end;
      except
        on E: Exception do
        begin
          showmessage(e.Message);
        end;  end;
    -------------------------------------------------------
    本回复由大傻的破玩意儿【CSDN's forum Explorer】完成!
    软件功能强大,速度超快!!支持中...
    软件下载地址:http://CoolSlob.ys168.com
      

  6.   

    TO:xzhifei
    我用了你的方法,但總提示:socket error # 11001我改用ICS的HttpCli控件,終於提示'401 Unthorized'了,代碼如下:
    HttpCli1.URL:= 'http://myaccount:[email protected]/dyndns/update?system=dyndns&hostname=yourhost.ourdomain.ext&61.129.47.77=ipaddress&wildcard=OFF';
      try
          HttpCli1.Get;
          except
          on E: EHttpException do
          Caption := 'Failed : ' +IntToStr(HttpCli1.StatusCode) + ' ' httpCli1.ReasonPhrase;
    把myaccount:mypass改為我的tempuser123456:164940正確資料(這是我剛申請的一臨時帳戶,大家可幫我試一下),這時卻什麼也沒有提示,域名地址也沒有成功更新,問題在哪裡?如何得到網站返回的訊息?請指教,謝謝.
    以下是網站相關的返回碼解釋:
    http://www.3322.org/dyndnspage/codes.htmlPre-Update Errors
    badauth Bad authorization (username or password)
    badsys The system parameter given was not valid. 
    badagent The useragent your client sent has been blocked at the access
    level. Support of this return code is optional. Update Complete 
    good Update good and successful, IP updated 
    nochg No changes, update considered abusive good或noschg后面会跟着所更新的IP地址Input Error Conditions
    notfqdn A Fully-Qualified Domain Name was not provided
    nohost The hostname specified does not exist
    nourl WebHop时,没有设置URL
    !donator The offline setting was set, when the user is not a donator,
    this is only returned once
    !yours The hostname specified exists, but not under the username
    currently being used
    !active The hostname specified is in a Custom DNS domain which has not
    yet been activated
    abuse The hostname specified is blocked for abuse; contact support to
    be unblockedServer Error Conditions
    numhost Too many or too few hosts found
    dnserr DNS error encounteredWait Conditions 
    wxxh Wait "xx" hours
    wxxm Wait "xx" minutes
    wxxs Wait "xx" seconds Emergency Conditions 
    911 Shutdown until notified otherwise via status.shtm 
      

  7.   

    我終於成功更新了,原來弄錯了網址的格式,正確的如下:
    HttpCli1.URL:= 'http://tempuser123456:[email protected]/dyndns/update?system=dyndns&hostname=tempuser123456.3322.org&myip=219.77.175.6&wildcard=OFF';
    HttpCli1.Get;
    現在還有個小問題:
    procedure TForm1.HttpCli1HeaderEnd(Sender: TObject);
    begin
    edit1.Text:=inttostr(httpcli1.StatusCode);  //可以得到返回碼'200',但這只表示登錄成功,不一定是更新域名成功,請問如何得到該網站更新成功後的返回訊息(根據該網站提供的資料應是Update Complete
    或good Update good and successful, IP updated )?
      

  8.   

    应该分析对方页面返回的html内容