gpt4 book ai didi

cURL 和包含冒号的密码

转载 作者:行者123 更新时间:2023-12-04 03:13:46 25 4
gpt4 key购买 nike

我正在使用 OpenSuse,我尝试通过 cURL 实用程序向 dashDB 本地环境上传数据。当我使用带有简单密码(没有“特殊”字符)的用户/密码时,它运行良好,但是当密码包含冒号时,它总是失败,无论以何种方式指定一对用户名/密码。

任务工作:

curl -X POST -H "Content-Type: multipart/form-data" -u "myuser:mypassword" "https://my_url" -F loadFile1=@"inputfile"

{"result":{...,"resultCode":"SUCCESS","errorMessageCode":"NONE","message":"LOAD started successfully."}

任务不起作用:
curl -X POST -H "Content-Type: multipart/form-data" -u "myuser:my:password" "https://my_url" -F loadFile1=@"inputfile"

Error 401: Basic authorization - bad header

我尝试了一些方法,例如转义冒号、用“%3A”替换它、将其放入 .netrc 文件中、将其直接放入 url ( https://myuser:my:password@my_url ) 等,但对于每种情况,它都失败了...

我很确定它不是 cURL 失败,因为当我通过 cURL 对 Cloudant 环境执行类似的任务时,密码中有一个冒号,它运行良好:
[i1058@lat111 ~]$ curl -X POST -H "Content-Type: application/json" -u "myuser:my:password" http://myuser.cloudant.com/mydb/_bulk_docs -d "@inputfile"
[{"ok":true,"id":"125ac5859f1e6f0de25e0ed33abd3198","rev":"1-c7e75ed33e6efae85d053acc1008c2c6"},...]

任何想法如何指定这样的密码?

编辑:

这是两次执行的标题:

工作执行:
[i1058@lat111 ~]$ curl -X POST -H "Content-Type: multipart/form-data" "https://user1:infotel0@192.168.42.219:8443/dashdb-api/load/local/del/USER1.EMPLOYEE?hasHeaderRow=false&delimiter=','&codePage=1208&hasDateTypes=true&dateFormat="YYYY-MM-DD"" -F loadFile1=@"outfile" -v
* About to connect() to proxy 192.168.42.219 port 3128 (#0)
* Trying 192.168.42.219...
* Connected to 192.168.42.219 (192.168.42.219) port 3128 (#0)
* Establish HTTP proxy tunnel to 192.168.42.219:8443
* Server auth using Basic with user 'user1'
> CONNECT 192.168.42.219:8443 HTTP/1.1
> Host: 192.168.42.219:8443
> User-Agent: curl/7.29.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection established
< Date: Wed, 22 Mar 2017 13:24:05 GMT
< Content-Type: text/html
< Proxy-Connection: Keep-Alive
< Via: 1.1 TO-PROXY.****
< Connection: close
<
* Proxy replied OK to CONNECT request
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* skipping SSL peer certificate verification
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
* subject: CN=localhost,OU=dsweb,O=ibm,C=us
* start date: Sep 08 17:37:29 2016 GMT
* expire date: Sep 08 17:37:29 2017 GMT
* common name: localhost
* issuer: CN=localhost,OU=dsweb,O=ibm,C=us
* Server auth using Basic with user 'user1'
> POST /dashdb-api/load/local/del/USER1.EMPLOYEE?hasHeaderRow=false&delimiter=','&codePage=1208&hasDateTypes=true&dateFormat=YYYY-MM-DD HTTP/1.1
> Authorization: Basic dXNlcjE6aW5mb3RlbDA=
> User-Agent: curl/7.29.0
> Host: 192.168.42.219:8443
> Accept: */*
> Content-Length: 5260
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------cbd0c10a30ab
>
< HTTP/1.1 100 Continue
< Content-Length: 0
< Date: Wed, 22 Mar 2017 13:24:06 GMT
< HTTP/1.1 200 OK
< Date: Wed, 22 Mar 2017 13:24:06 GMT
< X-Powered-By: Servlet/3.0
< Content-Type: application/json
< Content-Length: 423
< Set-Cookie: dsweb9302=00008jj9QpxOaIwwbWcGZddJ9V8:91d35242-6b49-4d90-9c18-5543188442ec; Path=/; HttpOnly
< Expires: Thu, 01 Dec 1994 16:00:00 GMT
< Cache-Control: no-cache="set-cookie, set-cookie2"
<
{"result":{"ROWS_COMMITTED":"","LOAD_LOGFILE":"loadlogs\/load_1982878712_USER1_EMPLOYEE_20170322-132406-UTC.txt","START_TIME":"20170322 13:24:06 UTC","LOAD_STATUS":"RUNNING","LOAD_ID":1982878712,"ROWS_LOADED":"","TABLE":"EMPLOYEE","ROWS_SKIPPED":"","END_TIME":"","SCHEMA":"USER1","ROWS_READ":"","ROWS_DELETED":"","ROWS_REJECTED":""},"resultCode":"SUCCESS","errorMessageCode":"NONE","message":"LOAD started successfully."}
* Connection #0 to host 192.168.42.219 left intact

然后是失败的:
[i1058@lat111 ~]$ curl -X POST -H "Content-Type: multipart/form-data" "https://user5:infotel%3A0@192.168.42.219:8443/dashdb-api/load/local/del/USER1.EMPLOYEE?hasHeaderRow=false&delimiter=','&codePage=1208&hasDateTypes=true&dateFormat="YYYY-MM-DD"" -F loadFile1=@"outfile" -v       
* About to connect() to proxy 192.168.42.219 port 3128 (#0)
* Trying 192.168.42.219...
* Connected to 192.168.42.219 (192.168.42.219) port 3128 (#0)
* Establish HTTP proxy tunnel to 192.168.42.219:8443
* Server auth using Basic with user 'user5'
> CONNECT 192.168.42.219:8443 HTTP/1.1
> Host: 192.168.42.219:8443
> User-Agent: curl/7.29.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection established
< Date: Wed, 22 Mar 2017 13:22:23 GMT
< Content-Type: text/html
< Proxy-Connection: Keep-Alive
< Via: 1.1 TO-PROXY.****
< Connection: close
<
* Proxy replied OK to CONNECT request
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* skipping SSL peer certificate verification
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
* subject: CN=localhost,OU=dsweb,O=ibm,C=us
* start date: Sep 08 17:37:29 2016 GMT
* expire date: Sep 08 17:37:29 2017 GMT
* common name: localhost
* issuer: CN=localhost,OU=dsweb,O=ibm,C=us
* Server auth using Basic with user 'user5'
> POST /dashdb-api/load/local/del/USER1.EMPLOYEE?hasHeaderRow=false&delimiter=','&codePage=1208&hasDateTypes=true&dateFormat=YYYY-MM-DD HTTP/1.1
> Authorization: Basic dXNlcjU6aW5mb3RlbDow
> User-Agent: curl/7.29.0
> Host: 192.168.42.219:8443
> Accept: */*
> Content-Length: 5260
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------69215f2ae3da
>
< HTTP/1.1 100 Continue
< Content-Length: 0
< Date: Wed, 22 Mar 2017 13:22:24 GMT
< HTTP/1.1 401 Unauthorized
< Date: Wed, 22 Mar 2017 13:22:24 GMT
< X-Powered-By: Servlet/3.0
< Content-Type: text/html;charset=UTF-8
< $WSEP: <-- Here there is something strange??
< Content-Language: en-US
< Set-Cookie: dsweb9302=0000ihijrP8WYwpQW8TCOzRB-gv:91d35242-6b49-4d90-9c18-5543188442ec; Path=/; HttpOnly
< Transfer-Encoding: chunked
< Expires: Thu, 01 Dec 1994 16:00:00 GMT
< Cache-Control: no-cache="set-cookie, set-cookie2"
* HTTP error before end of send, stop sending
<
Error 401: Basic authorization - bad header
* Closing connection 0
[i1058@lat111 ~]$ curl -X POST -H "Content-Type: multipart/form-data" "https://user5:infotel%3A0@192.168.42.219:8443/dashdb-api/load/local/del/USER1.EMPLOYEE?hasHeaderRow=false&delimiter=','&codePage=1208&hasDateTypes=true&dateFormat="YYYY-MM-DD"" -F loadFile1=@"outfile"
Error 401: Basic authorization - bad header

最佳答案

最近在使用 API 进行身份验证时遇到了类似的问题,该 API 需要 username:usergroup 作为用户名传递,中间有一个冒号。在 username:usergroup 周围添加双引号对我有用。

这不起作用:

-u "username:usergroup:password"

这确实有效:
-u ""username:usergroup":password"

因此,这应该适用于包含冒号的密码:
-u "username:"password""

关于cURL 和包含冒号的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42945629/

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