Guest User

Untitled

a guest
Jan 24th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. var request = require('request');
  2.  
  3.  
  4.  
  5. username = "",
  6. password = "",
  7. url = "http://207.188.73.88:8000/sap/opu/odata/sap/ZTEE_TIME_SRV/ZTEERESERVESet(Time=time'PT11H00M00S',Date=datetime'2014-03-11T00%3A00%3A00',Location='TAJ',Number=3)",
  8. auth = "Basic " + new Buffer(username + ":" + password).toString("base64");
  9.  
  10. request(
  11. {
  12. url : url,
  13.  
  14. headers : {
  15. "Authorization" : auth,
  16. 'x-csrf-token':'Fetch'
  17.  
  18. }
  19.  
  20. },
  21. function (error, response, body) {
  22. // console.log("JSON data " + response);
  23. // console.log("body" + body);
  24.  
  25. request(
  26. {
  27. url : url,
  28.  
  29. headers : {
  30.  
  31. "Authorization" : auth,
  32. "X-CSRF-TOKEN":"u6piLO58XoK6udOkQ5Naww=="
  33.  
  34. },
  35. method: 'POST',
  36. //Lets post the following key/values as form
  37. form: {
  38. Time:'PT11H00M00S',
  39.  
  40. Date:'2014-03-11T00%3A00%3A00',
  41. Location:'TAJ',
  42. Number:3 ,
  43. }
  44.  
  45. },
  46. function (error, response, body) {
  47. console.log(body);
  48. }
  49.  
  50.  
  51.  
  52.  
  53. );
  54. }
  55.  
  56.  
  57. );
  58.  
  59. let headers = {
  60. "Authorization": "Basic " + new Buffer(username + ":" + password).toString("base64"),
  61. "Content-Type":"application/json",
  62. "Accept":"application/json",
  63. "x-csrf-token":"Fetch" // get CSRF Token for post or update
  64. };
  65. // if you are using session vars
  66. if (req.session.headers && req.session.headers.cookie) {
  67. headers['Cookie'] = req.session.headers.cookie;
  68. } else {
  69. req.session.headers = {}; // initialize as object
  70. }
  71. let opts = {
  72. url: "https://{host}:{port}/sap/opu/odata/sap/MD_SUPPLIER_MASTER_SRV",
  73. qs: params1, // params set before, not set in the example
  74. headers: headers,
  75. json: true,
  76. }
  77. request(opts, (error: any, response: any, body: any): any => {
  78. if (!error && response.statusCode === 200) {
  79. if (response.headers["set-cookie"]) {
  80. req.session.headers.cookie = response.headers["set-cookie"]; // store Cookie in session
  81. headers['Cookie'] = req.session.headers.cookie; // set in headers for the next call. I guess this is the part you missed
  82. }
  83. if (response.headers['x-csrf-token']) {
  84. req.session.headers.csrf = response.headers['x-csrf-token']; // store csrf-token in session
  85. headers['x-csrf-token'] = req.session.headers.csrf; // set in headers for the next call
  86. }
  87.  
  88. let options: request.Options = {
  89. url: "https://{host}:{port}/sap/opu/odata/sap/MD_SUPPLIER_MASTER_SRV/C_BusinessPartnerSupplierEdit",
  90. method: 'POST',
  91. headers: headers,
  92. qs: params2, // params set before
  93. json: true,
  94. }
  95. request(options, (error: any, response: any, body: any): any => {
  96. res.json(body);
  97. });
  98. }
  99. });
Add Comment
Please, Sign In to add comment