Guest User

Untitled

a guest
May 27th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. export class AddTaskService {
  2.  
  3. constructor(private http: HttpClient) { }
  4. url = 'http://localhost:3000/tasks';
  5. posttasks(task) {
  6. return this.http.post<string>(this.url, JSON.stringify({ task: task }));
  7. }
  8.  
  9. }
  10.  
  11. app.use(bodyParser.urlencoded({ extended: true }));
  12. app.use(bodyParser.json());
  13.  
  14. router
  15. .route("/tasks")
  16. .post(function (req, res) {
  17. var taskModel = new taskSchema();
  18. taskModel.task = req.body.task;
  19. console.log(req.body);
  20. taskModel.save(function (err) {
  21. if (err) {
  22. res.send(err);
  23. }
  24. res.json({
  25. message: "nouvProj created!"
  26. });
  27. });
  28. });
  29.  
  30. Request URL: http://localhost:3000/tasks
  31. Request Method: POST
  32. Status Code: 200 OK
  33. Remote Address: [::1]:3000
  34. Referrer Policy: no-referrer-when-downgrade
  35.  
  36. Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
  37. Access-Control-Allow-Methods: GET, POST, PUT ,DELETE
  38. Access-Control-Allow-Origin: *
  39. Connection: keep-alive
  40. Content-Length: 31
  41. Content-Type: application/json; charset=utf-8
  42. Date: Sun, 27 May 2018 19:24:57 GMT
  43. ETag: W/"1f-NlZ/5EsK7Z/S3Ze5LQN4AonQQ90"
  44. X-Powered-By: Express
  45.  
  46. Accept: application/json, text/plain, */*
  47. Accept-Encoding: gzip, deflate, br
  48. Accept-Language: fr-FR,fr;q=0.9,ar-TN;q=0.8,ar;q=0.7,en-US;q=0.6,en;q=0.5
  49. Cache-Control: no-cache
  50. Connection: keep-alive
  51. Content-Length: 14
  52. Content-Type: text/plain
  53. DNT: 1
  54. Host: localhost:3000
  55. Origin: http://localhost:4200
  56. Pragma: no-cache
  57. Referer: http://localhost:4200/
  58. User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36
  59.  
  60. {task: "klj"}
  61. task
  62. :
  63. "klj"
  64.  
  65. const httpOptions = {
  66. headers: new HttpHeaders({
  67. 'Content-Type': 'application/x-www-form-urlencoded',
  68. })
  69. }
  70. return this.http.post<string>(this.url, JSON.stringify({ task: task }), httpOptions);
Add Comment
Please, Sign In to add comment