Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. function send (name) {
  2. http.request({
  3. host: '127.0.0.1',
  4. port: 3000,
  5. url: '/',
  6. method: 'POST'
  7. }, function (response) {
  8. response.setEncoding('utf8');
  9. response.on('data', function (data) {
  10. console.log('did get data: ' + data);
  11. });
  12. response.on('end', function () {
  13. console.log('n 33[90m request complete!33[39m');
  14. process.stdout.write('n your name: ');
  15. });
  16. response.on('error', function (error) {
  17. console.log('n Error received: ' + error);
  18. });
  19. }).end(query.stringify({ name: name})); //This posts the data to the request
  20. }
  21.  
  22. response.on('data', function (data) {
  23. console.log('did get data: ' + data);
  24. });
  25.  
  26. var query = require('querystring');
  27. require('http').createServer(function (request, response) {
  28. var body = '';
  29. request.on('data', function (data) {
  30. body += data;
  31. });
  32. request.on('end', function () {
  33. response.writeHead(200);
  34. response.end('Done');
  35. console.log('n got name 33[90m' + query.parse(body).name + '33[39mn');
  36. });
  37. }).listen(3000);
  38.  
  39. //console.log(response.statusCode); //Testing the response.
  40. //read the data
  41. response.on('data', function (chunk){
  42. body += chunk;
  43. });
  44. //ending the event.
  45. response.on('end', function() {
  46. range2.values = [[body]];
  47. console.log(body); // prints nothing!
  48. console.log('No more data in response.');
  49. })
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement