Node.js nodejs-URI%22无效-引号与%22匹配
我正在尝试使用节点中的请求模块,但一直遇到关于无效URI的问题 代码如下所示Node.js nodejs-URI%22无效-引号与%22匹配,node.js,uri,Node.js,Uri,我正在尝试使用节点中的请求模块,但一直遇到关于无效URI的问题 代码如下所示 request.put(JSON.stringify(systemUrl),{ json: { description: "xxxx", displayName: "xx", id: JSON.stringify(name),
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“%22”无效https://restofurl%22"
所以,这是来自systemUrl,这是我像这样构建的字符串。。
systemUrl='https://'+hostname+'/v1/id/name'+systemRole+'/'+defaultID;
其中主机名和系统角色是变量
如果我用字符串替换变量,并且有一个像“”这样的连续字符串,则相同的请求模块可以正常工作
我做错了什么
谢谢
变量中的Sam:
systemUrl='https://'+hostname+'/v1/id/name'+systemRole+'/'+defaultID代码>,您是否在名称后加上/号,可能应该是:'https://'+hostname+'/v1/id/name/'+systemRole+'/'+defaultID编码>并避免使用JSON.stringify。为什么要使用JSON.stringify?当我按原样使用systemUrl时,后端会抛出500个错误。因此,我开始尝试使用完整的字符串“”,而不是systemUrl变量。这是成功的。所以,我想它可能需要一个JSON字符串,这就是我看到这个关于%22无效URI的特殊错误的时候。看起来引号已转换为%22。抱歉,我在前面的帖子中错过了这一点。我的名称https://'+hostname+'/v1/id/name/'+systemRole+'/'+defaultID后面有一个“/”。这就是我所拥有的。