cURL-格式错误的请求,无法将字节转换为Unicode

问题描述 投票:0回答:1

我需要一小段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
curl microsoft-cognitive
1个回答
0
投票

您可以尝试在API参考中的Curl示例:Text Analytics API

此外,您也可以在此API参考中对其进行测试,在创建资源的区域中选择测试控制台,URL将如下所示:https://eastus.dev.cognitive.microsoft.com/docs/services/TextAnalytics-v3-0-Preview-1/operations/Languages/console

© www.soinside.com 2019 - 2024. All rights reserved.