curl 中的-u/--user username:password 在postman中如何使用

本文详细介绍了如何使用HTTP Basic认证进行身份验证,包括使用curl命令和Postman工具的具体操作步骤,以及PHP实现方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

username:password形式使用的是http authentication 中的basic形式  其他形式

下图是最简单的方法。感谢评论区提示。我一开始也没发现,这个确实更方便 

--------------------------以下弃用 ------------------------------------------

比如说  curl -X "POST" "https://xxxxx/oauth/token/" \
    --user username:secret \
    -d "scope=baseinfo"

将username:secret进行base64加密得到  dXNlcm5hbWU6c2VjcmV0  然后前面加上一个Basic和空格,

构造一个字符串形如: Basic dXNlcm5hbWU6c2VjcmV0

然后添加到postman的header中Authorization作为键,该字符串为值

 

另外附php方式, 用CURLOPT_USERPWD  和 header中Authorization方式都可以

./http_auth == Info: Trying 192.168.1.31... == Info: TCP_NODELAY set == Info: Connected to 192.168.1.31 (192.168.1.31) port 80 (#0) == Info: WARNING: Using weak random seed >> Header Out: POST /login.cgi HTTP/1.1 Host: 192.168.1.31 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7 Cache-Control: max-age=0 Connection: keep-alive Origin: http://192.168.1.31 Referer: http://192.168.1.31/ Upgrade-Insecure-Requests: 1 User-Agent: Chrome/123.0.0.0 Safari/537.36 Content-Length: 252 Expect: 100-continue Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryCsh0BrBqA4TyiE23; boundary=------------------------d16435452eaccacd == Info: Done waiting for 100-continue >> Data Out: --------------------------d16435452eaccacd Content-Disposition: form-data; name="username" config --------------------------d16435452eaccacd Content-Disposition: form-data; name="password" config --------------------------d16435452eaccacd-- << Header In: HTTP/1.1 200 OK << Header In: pires: Thu, 01 Jan 1970 00:00:00 GMT == Info: no chunk, no close, no size. Assume close to signal end << Header In: <!DOCTYPE html><html><head><!-- HTML meta refresh URL redirection --><meta http-equiv="refresh" content="0; url=/index.shtml"></head><body><p>Loading page, please wait: <a href="/index.shtml">Link to page</a></p></body></html><< Data In: <!DOCTYPE html><html><head><!-- HTML meta refresh URL redirection --><meta http-equiv="refresh" content="0; url=/index.shtml"></head><body><p>Loading page, please wait: <a href="/index.shtml">Link to page</a></p></body></html> == Info: Failed writing body (3069571632 != 226) == Info: Closing connection 0 curl_easy_perform() failed: Failed writing received data to disk/application write_callback:<!DOCTYPE html><html><head><!-- HTML meta refresh URL redirection --><meta http-equiv="refresh" content="0; url=/index.shtml"></head><body><p>Loading page, please wait: <a href="/index.shtml">Link to page</a></p></body></html>[makelink]/tmp/so/http-hzm
05-30
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值