gpt4 book ai didi

azure - 请求在 postman 中有效,但在curl中无效 - Azure App Insights API 以错误请求结束

转载 作者:行者123 更新时间:2023-12-03 07:03:33 24 4
gpt4 key购买 nike

我正在尝试根据此处的信息从 Azure App Insights API 查询数据 https://learn.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&timespan=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&timespan=PT12H' --header 'x-api-key: xxx'

我尝试包含来自 Postman 的所有 header (自动生成的 token 除外,我发现它不太可能是原因),但如果这可能不是原因,则这些 header 未包含在自动生成的 cUrl 中。它不起作用。欢迎对此问题有任何见解

最佳答案

尝试像这样的查询的 URLEncoding 值请求 %7C take 10

你的curl命令是:

curl --location --request GET 'https://api.applicationinsights.io/v1/apps/xxx/query?query=requests%20%7C%20take%2010&timespan=PT12H' --header 'x-api-key: xxx'

关于azure - 请求在 postman 中有效,但在curl中无效 - Azure App Insights API 以错误请求结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71862876/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com