我正尝试使用以下命令从终端发布curl请求以连接到DPD API:
$ sudo curl -H "Content-Type=application/json" -H "Authorization: Basic RFNNSVRIOk1ZUEFTU1" -H "GEOClient: account/12345" https://api.dpd.co.uk/user/?action=login
但我一直收到这个错误
Cannot GET /esgServer/user/?action=login
从文档中,我有这个:
3.1.1. API Login
URL=POST:/user/?action=login
Every API requires a geoSession except the Login which returns the geoSession which should be
passed into any further API calls.
This API sets up a session on the GeoPost servers in whic
h all
future requests validate against.
The API requires the username and password base64 encrypting
and passed across as an Authorization header in the HTTP request, example:
username = DSMITH
password = MYPASSWD
concatenate the username and password wit
h a colon in between and encrypt to base64 as a single
string:
DSMITH:MYPASSWD
this would result in a string of:
RFNNSVRIOk1ZUEFTU1dE
which can be applied to the http request as a header of:
Authorization: Basic RFNNSVRIOk1ZUEFTU1dE
A returning http respo
nse code of 401 means the username or password are incorrect
Supported HTTP Headers
content
-
type
None
Accept
application/json
Example Request is shown below:
POST /user/?action=login HTTP/1.1
Host: api.dpd.co.uk
Content
-
Type: application/json
Accept:
application/json
Authorization: Basic RFNNSVRIOk1ZUEFTU1dE
GEOClient: account/123456
Content
-
Length: 0
我错过了什么?
任何建议都将不胜感激
答案 0 :(得分:1)
我忘了在命令行中添加-X POST
所以
sudo curl -H "Content-Type=application/json" -H "Authorization: Basic RFNNSVRIOk1ZUEFTU1" -H "GEOClient: account/12345" -X POST https://api.dpd.co.uk/user/?action=login