如何将密钥指定为“授权"的 Restlet 客户 HTTP 标头 [英] How to specify Restlet customer HTTP header with key as "Authorization"

查看:65
本文介绍了如何将密钥指定为“授权"的 Restlet 客户 HTTP 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Restlet2.3 来运行 REST API 测试自动化.

I am using Restlet2.3 to run REST API test automation.

新功能有一个客户 HTTP 标头,用于将令牌传递给服务.

The new feature has a customer HTTP header to pass a token to the service.

Form headers = (Form)resource.getRequestAttributes().get("org.restlet.http.headers");
if (headers == null) {
    headers = new Form();
    resource.getRequestAttributes().put("org.restlet.http.headers", headers);
}           

...

headers.add(key, value);

代码有效.现在,客户 HTTP 标头被定义为授权".上面的代码似乎没有正确传递标头.而这并不是挑战计划所涉及的.

The code works. Now, the customer HTTP header is defined as "Authorization". The above code seems not passing the header properly. And this is not challengeScheme involved.

我在 SoapUI 和 Postman 上测试了这个场景.两者都有效.

I tested this scenario on SoapUI and Postman. Both work.

有人知道restlet支持这个吗?

Anyone knows that restlet support this?

推荐答案

实际上,在执行请求时,您无法使用 Restlet 覆盖像 Authorization 这样的标准标头.

In fact, you can't override standard headers like Authorization with Restlet when doing a request.

如果您想提供安全令牌,可以使用以下方法:

If you want to provide a security token, you could use this approach:

String pAccessToken = "some token";
ChallengeResponse challengeResponse = new ChallengeResponse(
                      new ChallengeScheme("", ""));
challengeResponse.setRawValue(pAccessToken);
clientResource.setChallengeResponse(challengeResponse);

这样,您将只有 Authorization 标头中的令牌(开头有一个空格 - 所以不要忘记修剪该值).

This way you'll have only the token in the Authorization header (with a space at the beginning - so don't forget to trim the value).

这篇关于如何将密钥指定为“授权"的 Restlet 客户 HTTP 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆