【问题标题】:Unable to access URL with Name but works with IP address无法使用名称访问 URL,但可以使用 IP 地址
【发布时间】:2020-05-21 12:16:49
【问题描述】:

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

问题是:这仅适用于 IP 而不适用于名称。 如果我尝试替换 IP 并输入 actual name 类似这样的内容,则会出现错误 你能告诉我是什么问题吗,或者你可以参考一些东西,我会读一下。

不适用于名称: "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);
    });

【问题讨论】:

  • 检查服务器上的 UserQuotations 文件,它是否位于此路径 http://tmSpn01.LayaMs.com:5432/Quotations/api/UserQuotations

标签: react-native fetch


【解决方案1】:

感谢您的回复。在 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); }

【讨论】:

    猜你喜欢
    • 2018-04-04
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 2013-06-04
    • 2021-04-07
    相关资源
    最近更新 更多