在 Restlet 客户端请求中使用参数

发布于 2024-07-11 15:50:37 字数 432 浏览 6 评论 0原文

我有:

Request request = new Request(Method.GET, "https://www.awebsite.com/login");
Client client = new Client(Protocol.HTTPS);
Response response = client.handle(request);
...
response.getEntity().write(System.out);

但我不知道如何设置登录参数...

代码

  • 我想要进行转义等的
  • 可以轻松地在 get/post 之间切换

作为一个基于 REST 的平台,我想我可能需要使用一些参数“representation”但这似乎有点奇怪。 我认为建立这种代表性例外是很常见的。

I have:

Request request = new Request(Method.GET, "https://www.awebsite.com/login");
Client client = new Client(Protocol.HTTPS);
Response response = client.handle(request);
...
response.getEntity().write(System.out);

But I don't know how to set the login parameters...

I want code that

  • does the escaping etc
  • can switch between get/post easily

Being a REST-based platform, I'm thinking I might need to use some parameter "representation" but that seems a bit strange. I'd think it would be common enough to build in this representational exception.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×眷恋的温暖 2024-07-18 15:50:37

如果“登录参数”是指使用 基本 HTTP 身份验证 发送凭据,则使用 Request.setChallengeResponse () 就像这样:

Request request = new Request(Method.GET, "https://www.awebsite.com/login");
request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC, username, password));

这适用于任何使用任何 HTTP 方法的请求。

但是,如果您尝试对其进行身份验证的服务器需要使用基本 HTTP 身份验证之外的某种协议的凭据,那么您需要解释该协议 - 即它是否使用 cookie、标头、令牌等。

顺便说一句,通过发布到 Restlet-Discuss 邮件列表,您可能会得到更快/更好的回复; 我在那里呆了一年半,这是一个很棒的社区。

If by "login parameters" you mean sending credentials using Basic HTTP Authentication, it's done using Request.setChallengeResponse() like so:

Request request = new Request(Method.GET, "https://www.awebsite.com/login");
request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC, username, password));

This will work for any Request, using any HTTP method.

If, however, the server to which you're trying to authenticate expects credentials using some protocol other than Basic HTTP Auth, then you'll need to explain that protocol -- i.e. does it use cookies, headers, tokens, etc.

BTW, you might get faster/better responses by posting to the Restlet-Discuss mailing list; I've been on there for a year and a half and it's a great community.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文