就是关于idHTTP控件的post方法,根本就运行不通!每次都报错“HTTP /1.1 405 method not allowed”,简直气死我了,还不如nmhttp呢,可是在d7里已经没有了!
var
  data: TIdMultiPartFormDataStream;
begin
  data := TIdMultiPartFormDataStream.Create;
  try
    data.AddFormField('username', 'zhangy');
    data.AddFormField('password', 'aaaaaa');
    IdHTTP1.HandleRedirects:=True;
    IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';    Memo1.Lines.Text := IdHTTP1.Post('HTTP://10.70.17.60/netoa', data);
  finally
    data.Free;
  end;
end;
根本运行不了,但是编译还没有错!运行时IdHTTP1.Post('HTTP://10.70.17.60/netoa', data);出错,大侠救救我吧,再不行我就要去上吊了

解决方案 »

  1.   

    應該是你用錯了TIdMultiPartFormDataStream!http://dev.csdn.net/article/29/29854.shtmconst
      LoginUrl='http://www.csdn.net/member/logon.asp';
      PostUrl='http://community.csdn.net/Expert/PostNew_SQL.asp';
      ReplyUrl='http://community.csdn.net/Expert/reply.asp';
      MsgUrl='http://community.csdn.net/message_board/postsend.asp';MyCookList:全局变量,取得当前用户的Cookie
    IdHTTP1: TIdHTTP;登录:
    function Logon(UserName, PassWord, CookieTime: string):boolean;
    var
      LoginInfo: TStrings;
      Response: TStringStream;
      i: Integer;
      Cookie:string;
    begin
      Result :=False;
      Cookie:='';
      MyCookList :='';
      Response := TStringStream.Create('');
      LoginInfo := TStringList.Create;
      try
        LoginInfo.Clear;
        LoginInfo.Add('login_name='+UserName);
        LoginInfo.Add('password='+PassWord);
        LoginInfo.Add('from=http://community.csdn.net/Expert/Forum.asp');
        LoginInfo.Add('cookietime='+CookieTime);
        LoginInfo.Add('x=0');
        LoginInfo.Add('y=0');                                                
        IdHTTP1.Request.Referer:='http://www.csdn.net/member/logon.asp';
        IdHTTP1.Request.From :='http://community.csdn.net/Expert/Forum.asp';
        try
          IdHTTP1.Post(LoginUrl,LoginInfo,Response);
        except
          showmessage('登陆失败');
        end;
        showmessage(Response.DataString);
        //从返回的页面中找出cookie
        for i :=0 to IdHTTP1.Response.RawHeaders.Count-1 do
        begin
          if UpperCase(Copy(IdHTTP1.Response.RawHeaders[i],1,10)) = 'SET-COOKIE' then
          begin
            Cookie :=Trim(Copy(IdHTTP1.Response.RawHeaders[i],12,MAXINT));
            Cookie :=Copy(Cookie,1,Pos(';',Cookie));
            MyCookList :=MyCookList+Cookie;
          //  showmessage(Cookie);
          end;
        end;
        IdHTTP1.Request.RawHeaders.Add('Cookie: '+MyCookList);
      finally
        LoginInfo.Free;
        Response.Free;
      end;
      if length(MyCookList)>200  then
        result:=True;
    end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
     var
      Fs : TFileStream;
    begin
      Fs := TFileStream.Create(IncludeTrailingBackslash(
         ExtractFilePath(Application.ExeName))+'document.txt',fmCreate);
      try
          with IdHTTP do
          begin
              Host := '192.168.0.3'; //Hôte
              Request.Username:='abc'; //Utilisateur
              Request.Password:='abc'; //Mot de passe
              Request.BasicAuthentication := True; //Auth. BASIC
              Get('192.168.0.3/',Fs); //demande le fichier
          end;
      finally
          Fs.Free;
      end;
    end;