我可以通过curl
执行以下命令成功创建一个地方:
$ curl -vX POST https://server/api/v1/places.json -d "
auth_token=B8dsbz4HExMskqUa6Qhn& \
place[name]=Fuelstation Central& \
place[city]=Grossbeeren& \
place[address]=Buschweg 1& \
place[latitude]=52.3601& \
place[longitude]=13.3332& \
place[washing]=true& \
place[founded_at_year]=2000& \
place[products][]=diesel& \
place[products][]=benzin \
"
服务器返回HTTP/1.1 201 Created
。
现在,我想将有效负载存储在一个如下所示的JSON文件中:
// testplace.json
{
"auth_token" : "B8dsbz4HExMskqUa6Qhn",
"name" : "Fuelstation Central",
"city" : "Grossbeeren",
"address" : "Buschweg 1",
"latitude" : 52.3601,
"longitude" : 13.3332,
"washing" : true,
"founded_at_year" : 2000,
"products" : ["diesel","benzin"]
}
所以我修改了要执行的命令,如下所示:
$ curl -vX POST http://server/api/v1/places.json -d @testplace.json
返回失败HTTP/1.1 401 Unauthorized
。为什么?
--data-binary
。