我正在嘗試根據此處的資訊從 Azure App Insights API 查詢資料https://docs.microsoft.com/en-us/rest/api/application-insights/query/get
該請求在 Postman 中也可以通過不同的查詢正常作業,但是當我在 Postman 中為請求生成 cUrl 并在 Linux 機器上運行它時它不起作用。它既不回傳輸出也不回傳錯誤。當詳細運行它時,我可以看到我收到 400(錯誤請求)錯誤。至少我是這么認為的,這是 -v 選項的輸出:
* Trying 20.79.68.149...
* TCP_NODELAY set
* Connected to api.applicationinsights.io (20.79.68.149) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, [no content] (0):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, [no content] (0):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, [no content] (0):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, [no content] (0):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS handshake, [no content] (0):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: C=US; ST=WA; L=Redmond; O=Microsoft Corporation; CN=api.applicationinsights.io
* start date: Jan 26 08:23:26 2022 GMT
* expire date: Jan 21 08:23:26 2023 GMT
* subjectAltName: host "api.applicationinsights.io" matched cert's "api.applicationinsights.io"
* issuer: C=US; O=Microsoft Corporation; CN=Microsoft Azure TLS Issuing CA 01
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* TLSv1.3 (OUT), TLS app data, [no content] (0):
* TLSv1.3 (OUT), TLS app data, [no content] (0):
* TLSv1.3 (OUT), TLS app data, [no content] (0):
* Using Stream ID: 1 (easy handle 0x5607e18a9220)
* TLSv1.3 (OUT), TLS app data, [no content] (0):
> GET /v1/apps/xxxxxxxxxxxxxx/query?query=query=requests | take 10×pan=PT12H HTTP/2
> Host: api.applicationinsights.io
> User-Agent: curl/7.61.1
> Accept: */*
> x-api-key: xxxxxxxxxxxxxx
>
* TLSv1.3 (IN), TLS handshake, [no content] (0):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, [no content] (0):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS app data, [no content] (0):
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
* TLSv1.3 (OUT), TLS app data, [no content] (0):
* TLSv1.3 (IN), TLS app data, [no content] (0):
< HTTP/2 400
< date: Wed, 13 Apr 2022 18:34:46 GMT
< strict-transport-security: max-age=15724800; includeSubDomains
< access-control-allow-origin: *
<
* Connection #0 to host api.applicationinsights.io left intact
這是 Postman 生成的請求:
curl --location --request GET 'https://api.applicationinsights.io/v1/apps/xxx/query?query=requests | take 10×pan=PT12H' --header 'x-api-key: xxx'
我嘗試包含所有來自 Postman 的標頭(除了自動生成的令牌,我認為這不太可能是原因),如果這可能不是原因,則這些標頭未包含在自動生成的 cUrl 中。它不起作用。歡迎對這個問題的任何見解
uj5u.com熱心網友回復:
像這樣嘗試查詢的 URLEncoding 值requests | take 10。
你的 curl 命令將是:
curl --location --request GET 'https://api.applicationinsights.io/v1/apps/xxx/query?query=requests | take 10×pan=PT12H' --header 'x-api-key: xxx'
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/459346.html
標籤:天蓝色 卷曲 邮差 azure-rest-api 洞察力
