C# 客户端到 Java 服务的 http 标头

发布于 2024-11-27 11:16:24 字数 809 浏览 2 评论 0原文

您好,我一直在尝试在 C# 中将 http 标头添加到 Web 客户端,我找了很多地方,但运气不佳,人们经常指向 Credentials 类,但是我只有 ClientCredentials,我的客户端还缺少 PreAuthenticate 字段?

该服务是用 Java 编写的,我可以添加 http 标头,如下所示

reqHeaders.put(HEADER_NAME_USERNAME, Collections.singletonList(USER_NAME));
reqHeaders.put(HEADER_NAME_PASSWORD, Collections.singletonList(PASSWORD));
((BindingProvider) webWS).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,reqHeaders);

但是我不知道如何在 c# 中执行此操作,我尝试过端点地​​址生成器、ClientCredential、windows.ClientCredential 基本上任何我可以找到用户名和密码的地方 当我在java中发出请求时,我在wireshark中捕获http数据包 看起来像这样,

+hypertext transfer protocol
+POST
  post stuff
 Password: mypass
 Username: username
 soapaction: ... and so on

我无法更改服务器端代码,我所知道的是,如果我可以添加两个标头,一个称为用户名,一个密码,其值将是 Sheening (阅读:获胜)

Hi ive been trying to add http headers to a webclient in c# , ive been looking alot of places and have had little luck often people point to a Credentials class however i only have ClientCredentials my client also missing is a PreAuthenticate field?

The service is written in Java and I can add http headers to that as follows

reqHeaders.put(HEADER_NAME_USERNAME, Collections.singletonList(USER_NAME));
reqHeaders.put(HEADER_NAME_PASSWORD, Collections.singletonList(PASSWORD));
((BindingProvider) webWS).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,reqHeaders);

However i have no idea how to do this in c# ive tried endpoint address builder, ClientCredential, windows.ClientCredential basically anywehre i can find a username and passsword
When i make a request in java i capture the http packet in wireshark
looks kinds like this

+hypertext transfer protocol
+POST
  post stuff
 Password: mypass
 Username: username
 soapaction: ... and so on

i cant change the server side code all i know is if i can add two headers one called username and one password with values ill be Sheening (read:winning)

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

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

发布评论

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

评论(1

悟红尘 2024-12-04 11:16:24

http://msmvps.com/blogs/paulomorgado/archive/2007/04/27/wcf-building-an-http-user-agent-message-inspector.aspx

这主要回答我的问题是,我没有编辑 app.config,而是在

webservice.Endpoint.Behaviors.add(new CustomBehavior(params)); 下添加了新定义的行为类;

http://msmvps.com/blogs/paulomorgado/archive/2007/04/27/wcf-building-an-http-user-agent-message-inspector.aspx

This mostly answered my problem, instead of editing the app.config though i jsut added the newly defined behaviour class under

webservice.Endpoint.Behaviors.add(new CustomBehavior(params));

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