大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本篇文章给大家分享的是有关nodejs中怎么对contact主数据进行修改,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
公司主营业务:成都做网站、成都网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联公司是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联公司推出西安免费做网站回馈大家。
代码如下:
var config = require("./mcConfig");var request = require('request');var url = config.tokenURL;console.log("user: " + config.user + " password: " + config.password); var getTokenOptions = { url: url, method: "GET", json:true, headers: { 'Authorization': 'Basic ' + new Buffer(config.user + ":" + config.password).toString('base64'), "content-type": "application/json", "x-csrf-token" :"fetch" } };function getToken() { return new Promise(function(resolve,reject){ var requestC = request.defaults({jar: true}); console.log("Step1: get csrf token via url: " + url ); requestC(getTokenOptions,function(error,response,body){ var csrfToken = response.headers['x-csrf-token']; if(!csrfToken){ reject({message:"token fetch error: " + error}); return; } console.log("Step1: csrf token got: " + csrfToken); resolve(csrfToken); }); }); }function updateContact(token){ return new Promise(function(resolve, reject){ var sPostData = "--batch_1f7d-bd35-caed" + "\n" + "Content-Type: multipart/mixed; boundary=changeset_8f9e-9a44-9f9e" + "\n" + "\n" + "--changeset_8f9e-9a44-9f9e" + "\n" + "Content-Type: application/http" + "\n" + "Content-Transfer-Encoding: binary" + "\n" + "\n" + "MERGE Consumers('02000A21209F1EE99CDF1A1FC9AA8065')?sap-client=100 HTTP/1.1" + "\n" + "Cache-Control: max-age=360" + "\n" + "sap-contextid-accept: header" + "\n" + "Accept: application/json" + "\n" + "Accept-Language: en" + "\n" + "DataServiceVersion: 2.0" + "\n" + "MaxDataServiceVersion: 2.0" + "\n" + "x-csrf-token: fQ2Pwfmf0K_LVYoKV9QYUw==" + "\n" + "Content-Type: application/json" + "\n" + //"Content-Length: 215" + "\n" + "\n" + "{\"YY1_CustomerType_ENH\":\"Jerry测试1\"}" + "\n" + "--changeset_8f9e-9a44-9f9e--" + "\n" + "\n" + "--batch_1f7d-bd35-caed--"; var requestC = request.defaults({jar: true}); var createOptions = { url: config.updateContactURL, method: "POST", json:false, headers: { "content-type": "multipart/mixed;boundary=batch_1f7d-bd35-caed", 'x-csrf-token': token }, body:sPostData }; requestC(createOptions,function(error,response,data){ if(error){ reject(error.message); }else { debugger; console.log("Contact updated successfully"); resolve(data); } }); }); } getToken().then(updateContact).catch((error) =>{ console.log("error: " + error.message); });
我在nodejs代码里把需要更改的字段值赋为"Jerry测试1”:
执行之后这个属性被成功更新了:
以上就是nodejs中怎么对contact主数据进行修改,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。