clienttmp.js 894 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var http=require('http');
  2. var post_data={"query":{"match":{"imtype":"LTCUS"}},"sort":[{"rtdatetime":{"order":"desc"}}],
  3. "size":3}//这是需要提交的数据
  4. var content=JSON.stringify(post_data);
  5. var options = {
  6. host: 'localhost',
  7. port: 8081,
  8. path: '/?a={1}',
  9. method: 'POST',
  10. headers:{
  11. 'Content-Type':'application/json',
  12. 'Content-Length':content.length
  13. }
  14. };
  15. options.path += '&b=2'
  16. console.log("post options:\n",options);
  17. console.log("content:",content);
  18. console.log("\n");
  19. var req = http.request(options, function(res) {
  20. console.log("statusCode: ", res.statusCode);
  21. console.log("headers: ", res.headers);
  22. var _data='';
  23. res.on('data', function(chunk){
  24. _data += chunk;
  25. });
  26. res.on('end', function(){
  27. console.log("\n--->>\nresult:",_data)
  28. });
  29. });
  30. req.write(content);
  31. req.end();