Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var request = require('request');
- username = "",
- password = "",
- 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)",
- auth = "Basic " + new Buffer(username + ":" + password).toString("base64");
- request(
- {
- url : url,
- headers : {
- "Authorization" : auth,
- 'x-csrf-token':'Fetch'
- }
- },
- function (error, response, body) {
- // console.log("JSON data " + response);
- // console.log("body" + body);
- request(
- {
- url : url,
- headers : {
- "Authorization" : auth,
- "X-CSRF-TOKEN":"u6piLO58XoK6udOkQ5Naww=="
- },
- method: 'POST',
- //Lets post the following key/values as form
- form: {
- Time:'PT11H00M00S',
- Date:'2014-03-11T00%3A00%3A00',
- Location:'TAJ',
- Number:3 ,
- }
- },
- function (error, response, body) {
- console.log(body);
- }
- );
- }
- );
- let headers = {
- "Authorization": "Basic " + new Buffer(username + ":" + password).toString("base64"),
- "Content-Type":"application/json",
- "Accept":"application/json",
- "x-csrf-token":"Fetch" // get CSRF Token for post or update
- };
- // if you are using session vars
- if (req.session.headers && req.session.headers.cookie) {
- headers['Cookie'] = req.session.headers.cookie;
- } else {
- req.session.headers = {}; // initialize as object
- }
- let opts = {
- url: "https://{host}:{port}/sap/opu/odata/sap/MD_SUPPLIER_MASTER_SRV",
- qs: params1, // params set before, not set in the example
- headers: headers,
- json: true,
- }
- request(opts, (error: any, response: any, body: any): any => {
- if (!error && response.statusCode === 200) {
- if (response.headers["set-cookie"]) {
- req.session.headers.cookie = response.headers["set-cookie"]; // store Cookie in session
- headers['Cookie'] = req.session.headers.cookie; // set in headers for the next call. I guess this is the part you missed
- }
- if (response.headers['x-csrf-token']) {
- req.session.headers.csrf = response.headers['x-csrf-token']; // store csrf-token in session
- headers['x-csrf-token'] = req.session.headers.csrf; // set in headers for the next call
- }
- let options: request.Options = {
- url: "https://{host}:{port}/sap/opu/odata/sap/MD_SUPPLIER_MASTER_SRV/C_BusinessPartnerSupplierEdit",
- method: 'POST',
- headers: headers,
- qs: params2, // params set before
- json: true,
- }
- request(options, (error: any, response: any, body: any): any => {
- res.json(body);
- });
- }
- });
Add Comment
Please, Sign In to add comment