How to specify Restlet customer HTTP header with key as “Authorization”

百般思念 提交于 2019-12-11 01:59:08

问题


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

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);

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.

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

Anyone knows that restlet support this?


回答1:


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);

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).



来源:https://stackoverflow.com/questions/35256898/how-to-specify-restlet-customer-http-header-with-key-as-authorization

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!