在 Restlet 客户端请求中使用参数
我有:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果“登录参数”是指使用 基本 HTTP 身份验证 发送凭据,则使用 Request.setChallengeResponse () 就像这样:
这适用于任何使用任何 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:
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.