Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add request.write(data) for POST/PUT/DELETE request #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edwineo
Copy link

@edwineo edwineo commented Sep 25, 2023

In my project, I found that the request always hang up and timeout when I proxy POST requests. But GET method is successful.

Finally I check the compat function and find the request.write() is not be called when I proxy a POST request.

reference:https://nodejs.org/dist/latest-v18.x/docs/api/http.html#requestwritechunk-encoding-callback

The request should be like that:

const http = require('http');

const body = {
   "data": {
     "channel" : "aaa",
     "appkey" : "bbb"
  },
  "sign" : "22334455",
  "token" : "bb667788"
};

const bodyString = JSON.stringify(body);

const headers = {
  'Content-Type': 'application/json',
  'Content-Length': bodyString.length
};

const options = {
  host: '127.0.0.1',
  port: 3005,
  path: '/Config',
  method: 'POST',
  headers: headers
};

const req = http.request(options, function(res) {
    ...
})

req.write(bodyString);
req.end();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant