我需要一段cURL才能从Windows 10上的命令提示符或GitBash运行,但收到"无效请求"错误。我正在调用 API,并且我已经以另一种方式测试了我的凭据,所以我知道这些是正确的。我在想也许我的代码片段在某些方面有缺陷。
注意:我无法错误地运行单引号,所以我在正文中转义了它们。我也不断收到通配错误,所以我逃脱了"{"和"["部分。我详细运行了命令,以获得更长的打印输出。我的代码段有误吗?
$ curl -v -X POST "https://<ACCOUNT-NAME>.cognitiveservices.azure.com/text/analytics/v3.0-preview.1/languages" -H "Ocp-Apim-Subscription-Key:<KEY>" -H "Content-Type:application/json" --data-raw "{documents:[{id:1,text:"This is a document written in English."},{id:2,text:"Este es un document escrito en Español."},{id:3,text:"这是一个用中文写的文件"}]}"
Note: Unnecessary use of -X or --request, POST is already inferred.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 52.229.16.14:443...
* TCP_NODELAY set
* Connected to <ACCOUNT-NAME>.cognitiveservices.azure.com (52.229.16.14) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
CApath: none
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.3 (IN), TLS handshake, Server hello (2):
{ [89 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [3692 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [365 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [102 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / <<...>>
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: CN=*.cognitive.microsoft.com
* start date: Apr 13 04:11:34 2020 GMT
* expire date: Apr 13 04:11:34 2021 GMT
* subjectAltName: host "<ACCOUNT-NAME>.cognitiveservices.azure.com" matched cert's "*.cognitiveservices.azure.com"
* issuer: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; OU=Microsoft IT; CN=Microsoft IT TLS CA 5
* SSL certificate verify ok.
} [5 bytes data]
> POST /text/analytics/v3.0-preview.1/languages HTTP/1.1
> Host: <ACCOUNT-NAME>.cognitiveservices.azure.com
> User-Agent: curl/7.65.3
> Accept: */*
> Ocp-Apim-Subscription-Key:<KEY>
> Content-Type:application/json
> Content-Length: 156
>
} [156 bytes data]
* upload completely sent off: 156 out of 156 bytes
{ [5 bytes data]
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Transfer-Encoding: chunked
< Content-Type: application/json; charset=utf-8
< x-envoy-upstream-service-time: 4
< apim-request-id: <<ID-REQUEST>>
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
< x-content-type-options: nosniff
< Date: Tue, 12 May 2020 02:30:08 GMT
<
{ [156 bytes data]
100 306 0 150 100 156 592 616 --:--:-- --:--:-- --:--:-- 1209{"error":{"code":"InvalidRequest","message":"Badly formed request: Unable to translate bytes [F1] at index 117 from specified code page to Unicode."}}
* Connection #0 to host <ACCOUNT-NAME>.cognitiveservices.azure.com left intact
您可以在 API参考:文本分析 API 中尝试 Curl 示例。
此外,您可以在此 API 参考中对其进行测试,在创建资源的区域中选择测试控制台,URL 将如下所示:https://eastus.dev.cognitive.microsoft.com/docs/services/TextAnalytics-v3-0-Preview-1/operations/Languages/console