在 HTTP 请求标头中插入用户凭据
我试图将用户凭据插入到 HTTP 请求标头中,然后通过 https 发送到 Web 服务,Web 服务又读取它们以进行授权...
客户端和服务都是用 Java 编写的。
在客户端,我执行以下操作:
ExampleImplService service = new ExampleImplService();
Example port = service.getExampleImplPort();
Map<String, Object> reqContext = ((BindingProvider) port).getRequestContext();
Map<String, List<String>> reqHeader = new HashMap<String, List<String>>();
reqHeader.put("Username", Collections.singletonList("user"));
reqHeader.put("Password", Collections.singletonList("password"));
reqContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeader);
System.out.println(port.somemethod());
如果我在添加后以编程方式转储 reqContext,我会看到添加的标头。但是通过 tcpmon,我可以看到,它们没有发送到 Web 服务...当然我也无法在 Web 服务中的任何地方找到它们。
知道我做错了什么吗?
I'm trying to insert user credentials into an HTTP request header which is then sent via https to a web service, which in turn reads them for authorization purposes...
Client and Service are both written in Java.
On the client side I do the following:
ExampleImplService service = new ExampleImplService();
Example port = service.getExampleImplPort();
Map<String, Object> reqContext = ((BindingProvider) port).getRequestContext();
Map<String, List<String>> reqHeader = new HashMap<String, List<String>>();
reqHeader.put("Username", Collections.singletonList("user"));
reqHeader.put("Password", Collections.singletonList("password"));
reqContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeader);
System.out.println(port.somemethod());
If I dump the reqContext after my additions programmatically I see the added headers. But via tcpmon, I can see, that they are not send to the web service... Naturally I can't find them anywhere in the web service either.
Any idea what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您正在使用 jax-ws 进行 Web 服务消费,所以我的答案将面向它
您可以像这样设置用户名和密码属性
如果这不起作用,您可能需要一个身份验证器(不适用于 Axis2 )
从此处复制
I believe you are using jax-ws for web service consumption so my answer will be oriented to it
You can set the username and password properties like this
If that doesn't work, you may need an Authenticator ( Doesn't work with Axis2 )
copied from here