&引用;“请求格式不正确”;尝试通过REST API获取Azure管理事件时

&引用;“请求格式不正确”;尝试通过REST API获取Azure管理事件时,api,azure,Api,Azure,根据那篇文章, 我正在尝试获取事件列表,执行以下操作: $ 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

根据那篇文章,

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

$ 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文章中的其他过滤器选项-结果是一样的


我做错了什么?

我相信问题出在您指定的日期范围内。请注意,您只能查询最近90天的数据,您正在查询去年的数据:

事件时间戳ge'2014-12-29T22:00:37Z'和事件时间戳le '2014-12-29T23:36:37Z'


请尝试更改日期/时间范围。否则,您的查询看起来很好。

哦,结果是我错误地调用了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代替'


而且它有效

它仍然不起作用:
curl-H“内容类型:应用程序/json”-H“授权:承载$TOKEN”https://management.azure.com/subscriptions/{subscribtion}/providers/microsoft.insights/eventtypes/management/values?api version=2014-04-01&\$filter=eventTimestamp ge'2015-11-25T22:00:37Z'
返回
HTTP错误400。请求的格式不正确。

嗯……我在谷歌邮递员中试用了您上面使用的那个,效果很好。但我删除了$之前的斜杠符号。让我在cURL中尝试一下。请尝试一下,让我知道它是否对您有效:)另一个可能会影响到这一点的因素是,我已经用为应用程序发行的令牌尝试过它,可能这就是问题所在……真的很奇怪!我也得到了400错误与卷曲,但它与谷歌邮递员。我刚刚尝试与谷歌邮递员,它的作品!(万岁!)哇,谢谢你,伙计!经过两天的尝试,这解决了问题:)
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'