gpt4 book ai didi

node.js - 如何防止 Restify 响应正文中出现多余的引号?

转载 作者:太空宇宙 更新时间:2023-11-03 22:44:15 25 4
gpt4 key购买 nike

我创建了一个简单的 restify 服务器,并且我尝试在响应正文中返回一个字符串:

server.post('/authurl', function authurl(req, res, next) {
res.send(dhs.getAuthorizeUrl());
return next();
});

但是,我注意到响应正文被双引号引起来,这是我没有要求的:

"https://some.url.com/oauth/v4/authorize?client_id=someid&scope=SOMESCOPE"

我已经验证这些额外的引号不是来自 getAuthorizeUrl 方法 - 它返回裸露的 URL。

如何去掉这些不需要的引号?

最佳答案

经过一些实验,我发现可以通过显式指定响应的内容类型来消除引号:

server.post('/authurl', function authurl(req, res, next) {
/*jslint unparam: true*/
res.contentType = "text/plain"; // needed so the platform doesn't add superfluous quotation marks around the URL in the response body
res.send(dhs.getAuthorizeUrl());
return next();
});

关于node.js - 如何防止 Restify 响应正文中出现多余的引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29152588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com