molnarg / node-http2

An HTTP/2 client and server implementation for node.js
MIT License
1.79k stars 187 forks source link

How send json? #249

Closed pvitaliy84 closed 6 years ago

pvitaliy84 commented 7 years ago

I try:

const request = require('http2');

const HOSTNAME="some_host";
const PORT="some_port";

const requestData = {
      message1: "Hello",
      message2: null
};

const json = JSON.stringify(requestData)

const options = {
      hostname: HOSTNAME,
      port: PORT,
      path: '/',
      method: 'POST',
      rejectUnauthorized: false,
      requestCert: true,
      agent: false,
      json: true,
      headers: {
        "Content-Type": "application/json",
        'Cache-Control': 'no-cache',
        'Content-Length': json.length
      },
      body: json
    };

request.request(options, (res) => {
      console.log(res)
});

no work. help please