通过Windows命令提示符成功发送的CURL Cookie失败,通过Windows批处理文件

时间:2017-06-14 12:34:22

标签: batch-file curl

如果我在Windows命令提示符下发送以下两个命令

命令1:

  

curl -d userId =“my.name”-d password =“my.password”   https://localhost:443/test/login -X POST -c“cookies.txt”-w   “%{response_code}” - k

命令2:

  

curl -F file1 = @“C:\ test.zip”https://localhost:443/test/upload -b   “cookies.txt”-w“%{response_code}” - k

在第二次通话中收到cookie。

如果我在Windows批处理文件中放入相同的两个命令,则在第二次调用中不会收到cookie。为什么呢?

更新

问题似乎与批处理文件中第二次调用中cookie的传递有关。 CURL在命令提示符中的第二次调用的详细输出(仅限第二个命令,批处理文件外)是:

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* 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 handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=localhost
*  start date: May 31 14:47:57 2017 GMT
*  expire date: May 31 00:00:00 2022 GMT
*  issuer: CN=localhost
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* 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
* Using Stream ID: 1 (easy handle 0x1c3ff9650f0)
> POST /test/upload HTTP/2
> Host: localhost:443
> User-Agent: curl/7.54.0
> Accept: */*
> Cookie: .AspNetCore.Password=VfDJ8DTHwtekoe5CixP71DROzvv-mAa0MfVBtNW71ESzGLMJ6txx48wVZU_w6nBczSP681tzYTUHLsgGVuvo2lx6pwTO-WJhpDvUcSxsUWKNurEqgZBRBo0RxLK4ubHCcncNnAbVCsc_McoKcEHFqy-cFvztqEDtNPlG7UTmI2685tfzM_W7csgUIOL9nfbo3T4cCytJXBfqCSrHRBkNN_wDD6QhDOpuiBKdy5cVhN4pXA2zh4WyCtOmrVHrJDwDDTdJEZMj7j59Y1AGT1diV8QivU2DuMcwbMrT7y3TmFRwhw5j30wukAV95MYw4357_87SX4XY9WwAJdncL0fMJ3OznVTVC9rUI3Tvi8M6KKfV3Lkb
> Content-Length: 735
> Content-Type: multipart/form-data; boundary=------------------------8ecfb7321f78c8b5
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 202
< cache-control: no-cache
< pragma: no-cache
< expires: -1
< server: Kestrel
* Replaced cookie .AspNetCore.Password="" for domain localhost, path /test, expire 1
< set-cookie: .AspNetCore.Password=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/test
< x-sourcefiles: =?UTF-8?B?RDpcUHJvamVjdHNcVmV0Q29tcGFzc1xjb2RlXGFzcFxWZXRDb21wYXNzLlVJXHNyY1xWZXRDb21wYXNzLlVJXGFwaVxkYXRhdXBsb2FkXHVwbG9hZA==?=
< x-powered-by: ASP.NET
< date: Wed, 14 Jun 2017 13:46:28 GMT
< content-length: 0
<
* Connection #0 to host localhost left intact
202

在批处理文件中(仅限第二个命令,完全相同的命令),详细输出为:

* Rebuilt URL to: ÔÇôb/
* Failed to convert ÔÇôb to ACE;
* Could not resolve host: ÔÇôb
* Closing connection 0
000curl: (6) Could not resolve host: ÔÇôb
* Rebuilt URL to: cookies.txt/
*   Trying 81.200.64.50...
* TCP_NODELAY set
* Connected to cookies.txt (81.200.64.50) port 80 (#1)
> POST / HTTP/1.1
> Host: cookies.txt
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 735
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------5fb5c68be6042795
>
* Empty reply from server
* Connection #1 to host cookies.txt left intact
000curl: (52) Empty reply from server
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 443 (#2)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* 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 handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=localhost
*  start date: May 31 14:47:57 2017 GMT
*  expire date: May 31 00:00:00 2022 GMT
*  issuer: CN=localhost
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* 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
* Using Stream ID: 1 (easy handle 0x1fda6c350f0)
> POST /test/upload HTTP/2
> Host: localhost:443
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 735
> Content-Type: multipart/form-data; boundary=------------------------bf4df70798c79cba
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 502
< cache-control: private
< content-type: text/html; charset=utf-8
< server: Microsoft-IIS/10.0
< x-sourcefiles: =?UTF-8?B?RDpcUHJvamVjdHNcVmV0Q29tcGFzc1xjb2RlXGFzcFxWZXRDb21wYXNzLlVJXHNyY1xWZXRDb21wYXNzLlVJXGFwaVxkYXRhdXBsb2FkXHVwbG9hZA==?=
< x-powered-by: ASP.NET
< date: Wed, 14 Jun 2017 13:52:09 GMT
< content-length: 4963
* Connection #2 to host localhost left intact
502

我删除-b "cookies.txt"后,Rebuilt URL to: ÔÇôb/输出就会消失。

1 个答案:

答案 0 :(得分:0)

问题与批处理文件的编码有关。非常尴尬,我之前没有检查过。我没有意识到该文件没有ANSI编码。有一个看起来像连字符的UTF-8字符。转换为ANSI编码后,角色显示出来。

相关问题