97
나는 성공적으로 다음 명령을 실행 curl
을 통해 장소를 만들 수 있습니다말풍선에 JSON 파일을 통해 페이로드를 전달하는 방법은 무엇입니까?
$ 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"]
}
그래서 나는 명령이 다음과 같이 실행되도록 수정이
HTTP/1.1 401 Unauthorized
을 반환 실패
$ curl -vX POST http://server/api/v1/places.json -d @testplace.json
. 왜?
나는'@ file.json'을 사용할 수 있다는 것을 알게 될 때까지'cat file.json'을'-d' 다음에 사용하려하고 문제가 생겼습니다. 고마워요 :) – shadi
@ 마타 수 제발 질문에보세요 [http://stackoverflow.com/questions/42021113/how-to-use-curl-to-access-the-github-graphql-api] –
참고 여러 개의 헤더가 필요하다면 우분투에서 bash로 테스트했을 때'-H' /'--header'를 여러 번 지정할 필요가 있습니다. –