为什么cURL不读取full@file并设置内容长度:8186?

为什么cURL不读取full@file并设置内容长度:8186?,curl,content-length,Curl,Content Length,我在Windows7上使用cURL来测试RESTful API 我的数据位于一个长度为16987个字符的JSON文件中 当我没有设置内容长度时,cURL假设content-length:8186,并且不发送整个JSON负载。我从服务器获得了意外的输入结束 当我设置-H“Content Length:17000”时,cURL似乎发送了前8186个字节,但没有正确构造请求正文(或其他内容)。。。服务器花了一些时间考虑这个问题,最后给出了400个错误请求 没有显式内容类型标头: C:\...>c

我在Windows7上使用cURL来测试RESTful API

我的数据位于一个长度为16987个字符的JSON文件中

当我没有设置内容长度时,cURL假设
content-length:8186
,并且不发送整个JSON负载。我从服务器获得了
意外的输入结束

当我设置
-H“Content Length:17000”时,
cURL似乎发送了前8186个字节,但没有正确构造请求正文(或其他内容)。。。服务器花了一些时间考虑这个问题,最后给出了
400个错误请求

没有显式内容类型标头:

C:\...>curl -v -X POST -H "Content-Type: application/json"  -H "Expect:" -H "Authorization=Bearer ...etc..." --data @quotedGood.json https://web.domain.com/NewApp/rest/invoice/
Note: Unnecessary use of -X or --request, POST is already inferred.
* STATE: INIT => CONNECT handle 0x60006a600; line 1103 (connection #-5000)
* Added connection 0. The cache now contains 1 members
*   Trying 192.168.0.0...
* STATE: CONNECT => WAITCONNECT handle 0x60006a600; line 1156 (connection #0)
* Connected to web.domain.com (192.168.0.0) port 443 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x60006a600; line 1253 (connection #0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /usr/ssl/certs/ca-bundle.crt
  CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* STATE: SENDPROTOCONNECT => PROTOCONNECT handle 0x60006a600; line 1267 (connection #0)
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*        subject: C=CA; ST=prov; L=town; O=Company; CN=*.domain.com
*        start date: Mar  5 17:57:58 2015 GMT
*        expire date: Nov 10 23:57:20 2018 GMT
*        subjectAltName: web.domain.com matched
*        issuer: C=US; O=Entrust, Inc.; OU=...etc...
*        SSL certificate verify ok.
* STATE: PROTOCONNECT => DO handle 0x60006a600; line 1288 (connection #0)
> POST /NewApp/rest/invoice/ HTTP/1.1
> Host: web.domain.com
> User-Agent: curl/7.47.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 8186
>
* upload completely sent off: 8186 out of 8186 bytes
* STATE: DO => DO_DONE handle 0x60006a600; line 1350 (connection #0)
* STATE: DO_DONE => WAITPERFORM handle 0x60006a600; line 1477 (connection #0)
* STATE: WAITPERFORM => PERFORM handle 0x60006a600; line 1487 (connection #0)
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 400 Bad Request
< Date: Mon, 05 Mar 2018 21:37:26 GMT
< Content-Type: application/json
< Set-Cookie: SERVERID=web8; path=/; HttpOnly; Secure
< Connection: close
< Transfer-Encoding: chunked
< X-Frame-Options: DENY
< Strict-Transport-Security: max-age=31536000; includeSubDomains
<
* STATE: PERFORM => DONE handle 0x60006a600; line 1645 (connection #0)
* Curl_done
* Closing connection 0
* The cache now contains 0 members
* TLSv1.2 (OUT), TLS alert, Client hello (1):
* Expire cleared
{"summary":"There was a problem with your invoice request. If you require technical assistance, please note the following identifier [NEWAPP-EX-646744087] to help trace the issue.","timestamp":"2018-03-05 16:37:26.105","errorMsgs":["Unexpected end-of-input in field name\n at [Source: org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl$InputStreamWrapper@74d44e80; line: 245, column: 205]"]}

传输编码
标题将忽略您的
内容长度
标题


根据建议,您可以尝试使用
-H“传输编码:标识”

这是我最终在Windows 7上的cmd提示符中得到的结果


curl——请求发布^
--网址http://127.0.0.1:8080/MyApp/rest/invoice ^
--标题“内容类型:应用程序/json”^
--标题“授权:某些专有身份验证代码”^
--标题“内容长度:9905”--标题“预期:”^
--数据二进制“@.\compressedGood.json”

compressedGood.json
是一个包含未转义、双引号字段和所有空格的文件,并且删除了
eol
s。比如:

{"externalId":null,"companyName":ACME,"companyProvince":ON,"salesFirstName":null,"salesLastName":null,"products":[ {"name":"Name of Product", ... etc  ... } ] }

我没有将此作为解决方案,但它使我走上了正确的道路,谢谢。
--数据二进制
为我解决了这个问题。我的文件要好得多(~100Kb),只有一部分会被发送(~44Kb)。我在想,由于我有一个二进制文件,它们可能在第一个
\0
时就停止了。无论如何,将文件标记为二进制文件是最简单的。
{"externalId":null,"companyName":ACME,"companyProvince":ON,"salesFirstName":null,"salesLastName":null,"products":[ {"name":"Name of Product", ... etc  ... } ] }