首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Windows命令提示符成功发送的CURL Cookies通过Windows批处理文件失败

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

Stack Overflow用户
提问于 2017-06-14 12:34:22
回答 1查看 577关注 0票数 0

如果我在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:

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

这些cookie在第二个呼叫中被接收。

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

更新:

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

代码语言:javascript
复制
*   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

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

代码语言:javascript
复制
* 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/输出就会消失。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-15 12:33:09

这个问题与批处理文件的编码有关。很尴尬我以前没查过这个。我没有意识到文件不是ANSI编码的。有一个像连字符的UTF-8字符。转换为ANSI编码后,字符就会显示出来。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44544955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档