gpt4 book ai didi

windows - git-bash 中的 curl 命令

转载 作者:可可西里 更新时间:2023-11-01 13:25:59 24 4
gpt4 key购买 nike

我有一个用 bash 编写并在 Linux (CentOS 7) 和 MacOS 上测试过的脚本。该脚本使用 cURL 与符合 REST API 的数据平台 (XNAT) 进行交互。

我希望 Windows 用户可以在 git-bash 中使用与 Git for Windows 打包在一起的相同脚本。不幸的是,在 git-bash 中使用 cURL 时似乎出现了问题。

我对 cURL 的第一次使用是检索 JSESSION cookie:

COOKIE=`curl -k -u $USERNAME https://theaddress/JSESSION`

在 Linux 上,这会要求用户输入密码并将 cookie 存储在 COOKIE 中。在 git-bash 中,发出命令会挂起,直到使用“ctrl + C”来中断它。奇怪的是,此时显示了密码查询消息,但为时已晚,脚本已终止。

我怀疑这可能与 CRLF 问题有关,但找不到我理解的有关此的信息。

欢迎任何指点!

谢谢

编辑:如果我像这样在命令中传递密码,上面的命令似乎工作正常:

COOKIE=`curl -k -u $USERNAME:$PASSWORD https://theaddress/JSESSION`

但是,正如此处指出的: Using cURL with a username and password?我宁愿避免让用户输入密码作为命令参数。

所以现在的问题是“为什么 cURL 在我使用第一个命令时不提示输入密码?”在 Windows 上的 git-bash 中,而该命令在 Linux 或 MacOS 中的行为与预期一致:

 COOKIE=`curl -k -u $USERNAME https://theaddress/JSESSION`

最佳答案

结束回答我自己的问题,希望这可能对其他人有用。

从 git-bash 中运行 cURL 时,这个问题似乎是一个已知问题,根据这个线程: https://github.com/curl/curl/issues/573

特别是,请参阅 dscho2015 年 12 月 30 日 的回答:

The problem is the terminal emulator we use with Git Bash since Git for Windows 2.5, MinTTY. This terminal emulator is not associated with a Win32 Console, therefore the user does not see anything when cURL wants to interact with the user via said Console.

此问题有解决方法,记录在此处: https://github.com/git-for-windows/build-extra/blob/master/ReleaseNotes.md#known-issues

解决方法是通过 winpty 运行 curl,如下所示:winpty curl [参数]

毕竟 CRLF 不是问题。

太棒了,git-bash 可能不是在 Windows 中以零努力运行我的 bash 脚本的 Elixir (tm)。唉……

关于windows - git-bash 中的 curl 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50724407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com