react-native - 无法使用名称访问 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);
});
解决方案
感谢回复。在 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);
}
推荐阅读
- linux - 在 grep 匹配的模式输出行前面打印文件名
- python - 按钮在 pycharm 中使用 python 和 tkinter 在新窗口中打开主页的重复窗口
- javascript - 对于 click() 方法,for 循环不能正常工作
- awk - 在图案后提取线条
- javascript - 填充同一文档中的 FORM 字段的可点击链接(但具有多个 FORM)
- image-processing - 预测编码如何帮助无损压缩?
- sql - 如何查看在 SQL 中复制的内容
- sql-server - 对选定行进行累积计算的 SQL SELECT
- android - 如何通过可重用的 RecyclerView 适配器使用 SQLite 数据
- pandas - 在机器学习中缩放 ID 列?