javascript - 如何将此获取响应转换为字符串?
问题描述
我有一个网址https://blah/configs.ini
它基本上看起来像这样:
[cdmglobal]
collectionHomepageImage = "upload"
customLandingPageAltText = ""
customLandingPageImage = "images/landingpage/small-monographiiif2.jpg
...
...
我需要那个customLandingPageImage 的名称。我的计划是将它放入一个字符串中,然后在 '/images/landingpage' 之后抓取该位,直到我到达 '.jpg'
我试过这个
let newSource = "http://blah/configs.ini";
fetch(newSource)
.then(function(response) {
let responseString = response.text();
console.log(responseString);
}).catch(function() {
console.log("error");
});
现在在 Chrome 开发工具中,它向我展示了:
Promise
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: "[cdmglobal]↵collectionHomepageImage = "upload"↵customLandingPageAltText = ""↵customLandingPageImage = "images/landingpage/small-monographiiif2.jpg
我真的只是想要那个 promiseValue 但它只以承诺值的形式返回它,而不是字符串。
解决方案
这应该有效;
let newSource = "http://blah/configs.ini";
fetch(newSource)
.then(function(response) {
response.text().then(function(responseString) {
console.log(responseString);
});
}).catch(function() {
console.log("error");
});
推荐阅读
- javascript - React-Draft-Wysiwyg:自动滚动新行
- latex - 如何将引文样式设置为仅在 pdf 中的姓氏?
- excel - 如何修复:“运行时错误 1005:对象‘_Workbook’的方法 SaveAs 失败”
- http2 - http1.1 中是否有任何内容表明我无法在请求正文发送完成之前发送响应?
- spring-boot - 使用 Spring Boot 将命令行工具的属性外部化
- python - 在python中获取setter状态
- sas - SAS中不平衡数据集的滚动窗口模型
- flutter - 使用 sqflite 包在 Flutter 中存储复杂对象
- python - Python读取csv文件并过滤数据
- angular - 无法读取所有标题以响应角度 2