| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 333 人关注过本帖
标题:delphi7使用Tidhttp设置HOST无效
只看楼主 加入收藏
赵丛
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2023-8-17
收藏
 问题点数:0 回复次数:0 
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的大佬能帮我一下么?
搜索更多相关主题的帖子: Request 请求 IdHttp api HOST 
2023-08-17 13:48
快速回复:delphi7使用Tidhttp设置HOST无效
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028747 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved