用delphi2010+indy10.5.5 自动发贴, 英文、数字都没问题。 但是一但涉及到中文,就全部都成问号了。有什么办法可以解决么?

解决方案 »

  1.   

    我采用了utf8Encode 在D7下是可以的。 但是在2010下,就是始终不行。
    而后采用了群里一位高人编写的针对d2009的indy10.5.5, 把原有版本卸掉后重新安装。 中文可正确编码。却变成无法提交了。
      

  2.   

    //发布函数
    function TForm1.Fabu: string;
    var
      str,__VIEWSTATE,__EVENTVALIDATION:string;
      mps:TIdMultiPartFormDataStream;
    begin
      result:='发布失败';  mps:=TIdMultiPartFormDataStream.Create;
      
      try
        str:=self.IdHTTP1.Get('http://my.xmhouse.com/esf/HouseInfosAdd.aspx?TradeType=1');
        __VIEWSTATE:=FindText(str,'id="__VIEWSTATE" value="','"');
        if __VIEWSTATE='' then exit;
        __EVENTVALIDATION:=FindText(str,'id="__EVENTVALIDATION" value="','"');
        if __EVENTVALIDATION='' then exit;    mps.AddFormField('__VIEWSTATE',__VIEWSTATE);
        mps.AddFormField('__EVENTVALIDATION',__EVENTVALIDATION);    mps.AddFormField('ctl00$ContentRight$ddlT_HouseInfos_BuildType','1'); 
        mps.AddFormField('ctl00$ContentRight$ddlT_HouseInfos_BuildSubType','1'); 
        mps.AddFormField('ctl00$ContentRight$ddlArea','3502030000'); 
        mps.AddFormField('ctl00$ContentRight$address','3502030001'); 
        mps.AddFormField('ctl00$ContentRight$txtZoneName',UTF8EncodeToShortString('东方明珠广场三期')); 
        mps.AddFormField('ctl00$ContentRight$txtZoneID','355'); 
        mps.AddFormField('ctl00$ContentRight$txtT_HouseInfos_Address',UTF8EncodeToShortString('愚民巷号')); 
        mps.AddFormField('ctl00$ContentRight$Latlng',''); 
        mps.AddFormField('ctl00$ContentRight$txtLoad','3502030001');
        mps.AddFormField('ctl00$ContentRight$txtT_HouseInfos_BuildArea','90'); 
        mps.AddFormField('ctl00$ContentRight$txtT_HouseInfos_UsedArea','70');  
        mps.AddFormField('ctl00$ContentRight$ddl_Room','1');    
        mps.AddFormField('ctl00$ContentRight$ddl_Hall','2');    
        mps.AddFormField('ctl00$ContentRight$ddl_Toilet','3'); 
        mps.AddFormField('ctl00$ContentRight$ddl_Balcony','4'); 
        mps.AddFormField('ctl00$ContentRight$ddlT_HouseInfos_PointTo','1'); 
        mps.AddFormField('ctl00$ContentRight$txtT_HouseInfos_Price','1000'); 
        mps.AddFormField('ctl00$ContentRight$ddlT_HouseInfos_PriceUnit','1'); 
        mps.AddFormField('ctl00$ContentRight$txtT_HouseInfos_CurFloor','1'); 
        mps.AddFormField('ctl00$ContentRight$txtT_HouseInfos_MaxFloor','2'); 
        mps.AddFormField('ctl00$ContentRight$txtT_HouseInfos_ExpireDay','3'); 
        mps.AddFormField('ctl00$ContentRight$ddlUsedYear','2011'); 
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_BasicEquip$0','on');  
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_BasicEquip$1','on');  
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_BasicEquip$2','on');  
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_AdvEquip$0','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_AdvEquip$1','on');   
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_AdvEquip$2','on');   
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_AdvEquip$3','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_AdvEquip$4','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_AdvEquip$5','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_AdvEquip$6','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_AdvEquip$7','on');    
        mps.AddFormField('ctl00$ContentRight$txtT_HouseInfos_OtherEquip',UTF8EncodeToShortString('美女'));    //设备情况,自定义
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_OverEquip$0','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_OverEquip$1','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_OverEquip$2','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_OverEquip$3','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_OverEquip$4','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_OverEquip$5','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_OverEquip$6','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_OverEquip$7','on');    
        mps.AddFormField('ctl00$ContentRight$chklT_HouseInfos_OverEquip$8','on');    
        mps.AddFormField('ctl00$ContentRight$txtT_HouseInfos_OtherOverEquip',UTF8EncodeToShortString('健身'));    
        mps.AddFormField('ctl00$ContentRight$rblT_HouseInfos_FitmentStauts','5');    
        mps.AddFormField('ctl00$ContentRight$rblT_HouseInfos_PropertyNum','1');      
        mps.AddFormField('ctl00$ContentRight$rblT_HouseInfos_IsHasPic','0');         
        mps.AddFormField('ctl00$ContentRight$rblT_HouseInfos_Evaluate','0');         
        mps.AddFormField('ctl00$ContentRight$txtT_HouseInfos_Note',UTF8EncodeToShortString('这可真是好房子,不来亏了')); 
        mps.AddFormField('ctl00$ContentRight$btn_addinfoH17',UTF8EncodeToShortString('提交'));    self.IdHTTP1.RedirectMaximum:=0;
        str:=(self.IdHTTP1.Post('http://my.xmhouse.com/esf/HouseInfosAdd.aspx?TradeType=1',mps));
        if pos('/esf/HouseInfosResult.aspx?iadd=1&ID=',IdHTTP1.Response.Location)>0 then
          result:='发布成功'
        else if pos('对不起,你已经发布过该信息了,不能再重复发布相同的信息',str)>0 then
          result:='你已经发布过该信息了,不能再重复发布相同的信息';      Memo1.Lines.Add(str);
      except
        self.IdHTTP1.Disconnect;
      end;
      mps.Free;
    end;这个是d2010版本, 在d7版本, 唯一有差别的是: UTF8EncodeToShortString -> UTF8EnCode, 在D7下正常发布。在d2010下发布不了。(前提:采用sczyq 大改正过后的indy10.5.5版本). 如果是d2010自带的indy版本,试了无数的转码函数都无法正确编码。在post后,通过抓包分析,中文全部都是???
      

  3.   


    D2010 改一下IdMultipartFormData.Pas单元里的Read函数就可以了!里边加上TEncoding.Default;
      

  4.   


    在单元里边找这个函数:
    function TIdMultiPartFormDataStream.IdRead(var VBuffer: TIdBytes; AOffset, ACount: Longint): Longint;修改里边的AppendString函数,共有三个函数,里边少最后一个.把函数最后一个参数设置为TEncoding.Default就可以了