我正在尝试在节点中使用请求模块,并且我一直在遇到有关无效URI的问题 代码如下所示
request.put(JSON.stringify(systemUrl),{
json: {
description: "xxxx",
displayName: "xx",
id: JSON.stringify(name),
url: jsonUrl
},
headers: {
"Content-Type": "application/json",
"accept": "application/json",
"Authorization": requestauth
},
strictSSL: false
}, function (error, response, body) {
if (!error) {
//console.log("The error is " + error);
console.log("The status code for system role unsuccessful is " + response.statusCode);
console.log("The body for unsuccessful call is " + body);
callback(error,"setting system role unsuccessful");
}
else {
console.log("Setting the role is successful \n");
console.log("The response is \n" + response);
console.log("The error is " + error);
//console.log("The body for unsuccessful call is " + body);
callback(null,"Setting system role is successful");
}
});
但我一直得到例外 错误是错误:无效的URI“%22https:// restofurl%22”
所以,这来自systemUrl,这是我构建的字符串.. systemUrl ='https://'+ hostname +'/ v1 / id / name'+ systemRole +'/'+ defaultID; 其中hostname和systemRole是变量。
如果我用字符串替换变量并且有一个连续的字符串如“https://restofUrl”,那么相同的请求模块工作正常。
我做错了什么?
由于 萨姆
答案 0 :(得分:0)
在你的变量中:
systemUrl = 'https://' + hostname + '/v1/id/name' + systemRole + '/' + defaultID;
,你是在点名吗? ,可能它应该是:'https://' + hostname + '/v1/id/name/' + systemRole + '/' + defaultID;
并避免使用JSON.stringify。