You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following this article, this is how my code looks like so far:
const fs = require('fs'), https = require('https'), fetch = require('node-fetch')
const sslConfiguredAgent = new https.Agent({
cert: fs.readFileSync(path.resolve(__dirname, '../ApplePushServices.pem'), `utf-8`),
passphrase: CERTIFICATE_PASS,
keepAlive: false // switch to true if you're making a lot of calls
})
fetch('https://api.development.push.apple.com/3/device/DEVICE_TOKEN', {
method: 'POST',
headers: {
'apns-topic': 'PROJECT_BUNDLE_IDENTIFIER',
'apns-expiration': '1',
'apns-priority': '10',
'Content-Type': 'application/json; charset=UTF-8'
},
agent: sslConfiguredAgent,
body: JSON.stringify({
"aps": {
"alert": {
"title": "Game Request",
"body": "Bob wants to play poker"
},
"sound":"default"
},
"data": "some custom data"
})
})
.then(async res => {console.log("OK", res)})
.catch(err => {console.log("ERROR", err)});
I get this result:
ERROR FetchError: request to https://api.development.push.apple.com/3/device/xxxxxx failed, reason: Parse Error: Expected HTTP/
at ClientRequest.<anonymous> (/Users/bidetaggle/Desktop/boxbeat-media-server/server/node_modules/node-fetch/lib/index.js:1455:11)
at ClientRequest.emit (events.js:315:20)
at TLSSocket.socketOnData (_http_client.js:514:9)
at TLSSocket.emit (events.js:315:20)
at addChunk (_stream_readable.js:302:12)
at readableAddChunk (_stream_readable.js:278:9)
at TLSSocket.Readable.push (_stream_readable.js:217:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:186:23) {
type: 'system',
errno: 'HPE_INVALID_CONSTANT',
code: 'HPE_INVALID_CONSTANT'
}
What am I missing in here?
My Environment
software
version
node-fetch
^2.6.0
node
v14.4.0
npm
6.14.4
Operating System
Mac OS Catalina
The text was updated successfully, but these errors were encountered:
Hi, thank you for your help. Because I also have to handle --cert option I decided to run directly curl from the system to go ahead faster. I see that http2 is on the v3 roadmap.
I link the issue here as a vote for the feature: #668
Hello,
I'd like to convert the following (tested and working) curl command to node-fetch:
Following this article, this is how my code looks like so far:
I get this result:
What am I missing in here?
My Environment
The text was updated successfully, but these errors were encountered: