delphi7使用Tidhttp设置HOST无效

        当我在请求远程服务器的时候需要去设置win系统中的hosts文件:IP 域名。然后使用域名去请求,我就想直接使用IP去请求服务。发现404通过查找后发现API文档中有一个头属性host才能去直接使用IP去请求。

HOSTS文件设置(列子)

127.0.0.1 BBB 

直接使用 http://127.0.0.1/api/plans 不行 使用url := 'http://BBB/api/plans'可以

IdHttp := TIdHTTP.Create(nil);
  try
    IdHttp.HTTPOptions := IdHttp.HTTPOptions + [hoKeepOrigProtocol];
    IdHttp.ProtocolVersion := pv1_1;
    IdHttp.Request.ContentType := 'application/json';
    IdHttp.Request.AcceptEncoding := 'gzip, deflate, br';
    IdHttp.Request.Connection := 'keep-alive';
    IdHttp.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
    IdHttp.Request.Accept := '*/*';
    // 添加请求参数和请求体初始化
    jo := SO(date);
    RequestStream := TStringStream.Create(jo.AsJSON);
    try
      //IdHttp.Request.RawHeaders.Values['host']:='BBB';
      ResponseStr := IdHttp.Post(url, RequestStream);
      // 网页中存在中文时,需要进行UTF8解码
      ResponseStr := UTF8Decode(ResponseStr);
      Result := ResponseStr;

    except
      on E: Exception do
      begin
        ShowMessage(E.Message);
        Result := '';
      end;
    end;

  finally
    IdHttp.Free;
    RequestStream.Free;
  end;

设置IdHttp.Request.RawHeaders.Values['host']:='BBB';不行

IdHttp.Request.Host:='BBB';也不可以

IdHttp.Request.CustomHeaders.Values['host']:='BBB';也不可以

IdHttp.Request.CustomHeaders.Add('host: BBB');还是不行

我快逼疯了,有现在使用delphi7的大佬能帮我一下么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值