api - 尝试通过 REST API 获取 Azure 管理事件时出现 "The request is badly formed"

标签 api azure

根据那篇文章https://msdn.microsoft.com/en-us/library/azure/dn931934.aspx ,

我正在尝试获取执行以下操作的事件列表:

$ curl -X GET -H  "Content-Type:application/json"  -H "Authorization:Bearer $TOKEN" "https://management.azure.com/subscriptions/SUBSCRIP-TI0N-xxxx-xxxx-xxxxxxxxxxxx/providers/microsoft.insights/eventtypes/management/values?api-version=2014-04-01&\$filter=eventTimestamp ge '2014-12-29T22:00:37Z' and eventTimestamp le '2014-12-29T23:36:37Z' and eventChannels eq 'Admin, Operation'" -v


* Hostname was NOT found in DNS cache
*   Trying 23.97.164.182...
* Connected to management.azure.com (23.97.164.182) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
* Server certificate: management.azure.com
* Server certificate: Microsoft IT SSL SHA2
* Server certificate: Baltimore CyberTrust Root
> GET /subscriptions/SUBSCRIP-TI0N-xxxx-xxxx-xxxxxxxxxxxx/providers/microsoft.insights/eventtypes/management/values?api-version=2014-04-01&$filter=eventTimestamp ge '2014-12-29T22:00:37Z' and eventTimestamp le '2014-12-29T23:36:37Z' and eventChannels eq 'Admin, Operation' HTTP/1.1
> User-Agent: curl/7.37.1
> Host: management.azure.com
> Accept: */*
> Content-Type:application/json
> Authorization:Bearer {mytokenthere}
>

但结果是:

< HTTP/1.1 400 Bad Request
< Content-Type: text/html; charset=us-ascii
* Server Microsoft-HTTPAPI/2.0 is not blacklisted
< Server: Microsoft-HTTPAPI/2.0
< Date: Tue, 01 Dec 2015 10:06:38 GMT
< Connection: close
< Content-Length: 311
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request</h2>
<hr><p>HTTP Error 400. The request is badly formed.</p>
</BODY></HTML>

但这似乎与 msdn 示例中的请求完全相同。

我认为过滤器参数一定有问题,当我修改它时,响应指出过滤器参数无效:

curl -X GET -H  "Content-Type:application/json"  -H "Authorization:Bearer $TOKEN" "https://management.azure.com/subscriptions/SUBSCRIP-TI0N-xxxx-xxxx-xxxxxxxxxxxx/providers/microsoft.insights/eventtypes/management/values?api-version=2014-04-01"
<Error xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure"><Code>BadRequest</Code><Message>The $filter query parameter value is invalid.</Message></Error>

我还尝试了 msdn 文章中的其他过滤选项 - 结果是相同的。

我做错了什么?

最佳答案

哦,原来我错误地调用了curl,这个问题实际上很愚蠢:)

这就是它的工作原理:

curl -H  "Accept:application/json"  -H "Authorization: Bearer $TOKEN" 'https://management.azure.com/subscriptions/{subscription_id}/providers/microsoft.insights/eventtypes/management/values?api-version=2014-04-01&$filter=eventTimestamp%20ge%20%272015-11-29T22:00:37Z%27'

因此使用 %20 代替空格,使用 %27 代替 '

它有效!

关于api - 尝试通过 REST API 获取 Azure 管理事件时出现 "The request is badly formed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34018209/

相关文章:

ios - Swift 2 - 如何从 Alamofire.responseJSON 获取数据

javascript - CORS 的概念,我应该强制使用 Origin header 吗?

azure - transactionScope 如何影响 Azure 队列?

javascript - Node |将 GET 连接到成功发布的数据

database - 以编程方式访问汽车经销商库存

手动触发时找不到 Azure Synapse Pipeline

azure - 从 Azure Graph API 检索 itemAttachment

通过 CLI 在现有 vnet 中创建 Azure 容器实例

azure - LUIS 中的 400 错误请求 : Cannot find the specified subscription

php - JSON 到 MySql 使用 PHP