powershell - 对 Mapbox 的 geojson API 请求的 powershell 解析
问题描述
我一直在使用内联 Windows 10 Powershell 命令成功下载静态 Google 和 Mapbox png 图像,但无法让 Powershell 成功传递 geojson 对象以利用 Mapbox 中的覆盖功能。我不是 Powershell 专家用户,我希望我需要添加更多语法才能使其正常工作?
以下代码取自 Mapbox 在线 curl 示例,可以正常工作:
powershell -command "(New-Object System.Net.WebClient).Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials";"
Invoke-RestMethod -Uri 'https://api.mapbox.com/styles/v1/mapbox/streets-v10/static/-73.99,40.70,12/500x300?access_token=<access-token-removed-here>'
-outfile test_no_overlay.png"
但以下 Mapbox curl 示例使用 geojson 哈希表格式包含覆盖标记(将通过浏览器工作)不能通过 Powershell 工作:
powershell -command "(New-Object System.Net.WebClient).Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials";"
Invoke-RestMethod -Uri 'https://api.mapbox.com/styles/v1/mapbox/streets-v10/static/geojson(%7B%22type%22%3A%22Point%22%2C%22coordinates%22%3A%5B-73.99%2C40.7%5D%7D)/-73.99,40.70,12/500x300?access_token=<access-token-removed-here>'
-outfile test_overlay.png"
报告的错误是:
Invoke-RestMethod : {"message":"Failed parsing geojson"} At line:1 char:110 + ... redentials; Invoke-RestMethod -Uri ' https://api.mapbox.com/styles/v1/ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod] , WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
此非代理版本也适用于 Powershell 提示符:
$response=Invoke-RestMethod -Uri 'https://api.mapbox.com/styles/v1/mapbox/streets-v10/static/geojson(%7B%22type%22%3A%22Point%22%2C%22coordinates%22%3A%5B-73.99%2C40.7%5D%7D)/-73.99,40.70,12/500x300?access_token=<access-token-removed-here>'
-outfile test_overlay.png
所以看来我需要克服一个语法问题才能使其以单行 CMD 格式执行?
解决方案
推荐阅读
- php - 计算嵌套数组中的元素数量
- windows - Windows 下 npm 下 HOME 环境变量变化
- mongodb - MongoDB compass - 从文档中的 3 个字段及其值中获取具有最大值的字段名称(键)
- python - 如何从 GUI 中获取信息以使用 pyautogui 自动执行任务
- excel - How to copy and paste dynamic table values in next empty cell?
- node.js - 在 multer s3 模块中调整图像大小
- javascript - 使用动态函数创建代理
- r - Frequency table but custom function instead of default count?
- css - Vis Network + Vuetify Tabs - 网络不会填满屏幕
- python - TypeError:在 CMD 中调用 pip 时,“模块”对象不可调用