首页 > 解决方案 > 无法使用名称访问 URL,但可以使用 IP 地址

问题描述

我正在使用以下 fetch 命令,它工作正常。

问题是:这仅适用于 IP 而不适用于名称。如果我尝试替换 IP 并输入类似这样的实际名称,那么它会抛出错误你能告诉我是什么问题吗,或者你能参考一些东西,我会读到的。

不使用名称:“http://tmSpn01.LayaMs.com:5432 /Quotations/api/UserQuotations

使用 IP 地址:

 fetch('http://192.78.87.89:3472/Quotations/api/UserQuotations')
    .then((response) => response.json())
    .then((responseJson) => {
      return responseJson.articles;
    })
    .then( articles  => {
      setArticles(articles);
      //console.log(articles);
      setLoading(false);
    })
    .catch( error => {
      console.error(error);
    });

标签: react-nativefetch

解决方案


感谢回复。在 Post man 中,它也使用 IP 地址和名称。我去了你提到的那个文件。它是我用 C 语言开发的 WebApi。它看起来像以下。关于 IP 地址的名称没有什么可提及的。
[HttpPost] [Route("api/UserQuotations")] public IHttpActionResult UserQuotations(Parameter paramObj) { string response = ""; List<object> quotationList = new List<object>(); QuotationClient client = InitializeService(paramObj.user, paramObj.password, paramObj.EndpointAddress); --- SOme line of code--- return Ok(List); }


推荐阅读