2015-01-12 2 views
0

푸시 알림을 보낼 cURL 명령을 실행하려고합니다. 내가 할 cURL 명령을 가지고 있지만 지금은 노드에서 실행해야합니다.요청을 사용하여 nodejs에서 Urban Airship cURL 명령을 실행 하시겠습니까?

curl -v -X POST -u "<shared>:<secret>" -H "Content-type: application/json" -H "Accept: application/vnd.urbanairship+json; version=3;" --data '{"audience" : {"tag":[testTag]}, "device_types" : "all", "notification" : {"alert": "Test push notification"} }' https://go.urbanairship.com/api/push/" 

그리고 노드 내 현재 요청은 다음과 같습니다 :

현재 컬은

  request({ 
       url: "https://go.urbanairship.com/api/push/", 
       method: "POST", 
       json: { 
       audience : { 
        tag : [ "testTag" ] 
       }, 
       device_types : "all", 
       notification : { 
        alert : "Test push notification" 
       } 
       } 
      }); 

내가 공유 비밀, 또는이 가장 인 경우에도 전달하는 방법을 잘 모르겠어요 연습.

답변

0

This request example은 HTTP 인증을 수행하는 방법을 보여줍니다. 요약하면 을 request() 옵션에 추가하십시오.

example for adding custom HTTP headers도 있습니다. 귀하의 request() 옵션에 headers: { 'Accept': 'application/vnd.urbanairship+json; version=3;' }을 설정하는 것만 큼 간단합니다. 현재 json 옵션을 사용하면 Content-Type 헤더가 request으로 자동 설정됩니다.

관련 문제