用于发出POST请求的Curl命令

Bes*_*esi 26 curl http

我在我的终端,我想向给POST定的URL 发送请求.我已经使用REST客户端对此进行了测试,因此我知道参数有效.

所以我想说要POST以下参数:

  • 用户名=托尼
  • 密码=秘密

到我的网址:https://exmaple.com/login/

我在我的终端尝试了以下curl命令(我正在使用OSX Lion)

curl --data "username=tony&password=secret" http://exmaple.com/login/
Run Code Online (Sandbox Code Playgroud)

500 Server Error从服务器回来了,所以我现在想的是REST客户端和curl命令之间可能有所不同.

谢谢你的帮助

更新:我正在使用https服务.我是否必须调整我的curl命令来解决这个问题?

rus*_*sau 23

试试这个

curl -F username=tony -F password=secret http://exmaple.com/login/
Run Code Online (Sandbox Code Playgroud)

-F(引用)应该和--data一样吗?可能问题出在webapp上.

也许您正在使用的应用程序使用基本身份验证进行身份验证?试试这个:

curl --user name:password http://exmaple.com/login/
Run Code Online (Sandbox Code Playgroud)

  • -F执行多部分发布,而--data执行标准应用程序/ x-www-form-urlencoded,因此如果一个人不能正常工作,那么很有可能. (5认同)