简体   繁体   English

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

[英]CURL Cookies successfully sent via Windows Command Prompt fail via Windows batch file

If I send the below two commands within a Windows Command Prompt 如果我在Windows命令提示符中发送以下两个命令

Command 1: 指令1:

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

Command 2: 指令2:

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

The cookies are received in the second call. 在第二个调用中接收到cookie。

If I put the same two commands in a Windows batch file, the cookies are not received in the second call. 如果将相同的两个命令放在Windows批处理文件中,则在第二个调用中不会收到cookie。 Why? 为什么?

Update: 更新:

The problem seems to be related to the passing of the cookie in the second call within the batch file. 该问题似乎与在批处理文件内第二次调用中传递cookie有关。 CURL's verbose output for the second call in Command Prompt (2nd command only, outside batch file) is: 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

Inside the batch file (2nd command only, exact same command) the verbose output is: 在批处理文件中(仅第二个命令,完全相同的命令),详细输出为:

* 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

As soon as I remove -b "cookies.txt" the Rebuilt URL to: ÔÇôb/ output goes away. 删除-b "cookies.txt"-b "cookies.txt"Rebuilt URL to: ÔÇôb/消失Rebuilt URL to: ÔÇôb/输出。

The problem was related to the encoding of the batch file. 问题与批处理文件的编码有关。 Very embarrassing that I didn't check this before. 非常尴尬的是我之前没有检查过。 I didn't realise the file wasn't ANSI encoded. 我没有意识到该文件不是ANSI编码的。 There was a UTF-8 character that looked like a hyphen. 有一个看起来像连字符的UTF-8字符。 After converting to ANSI encoding, the character showed itself. 转换为ANSI编码后,该字符显示出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM