【发布时间】:2015-10-07 06:10:47
【问题描述】:
我有以下代码向服务器发出 POST 请求。但是,Web 服务器可以是 Apache 或 IIS。
Client client = new Client(new Context(), Protocol.HTTP);
ClientResource resource = new ClientResource(url);
resource.setRetryOnError(false);
resource.setNext(client);
resource.setChallengeResponse(ChallengeScheme.HTTP_BASIC,userName,pwd);
response = resource.post(representation);
以下代码适用于 apache,但对于 IIS 失败并出现以下错误:
WARNING: Couldn't find any helper support the HTTP_NTLM challenge scheme.
WARNING: Couldn't find any helper support the HTTP_Negotiate challenge scheme.
Exception in thread "main" Unauthorized (401) - The request requires user authentication
可能原因是 apache 使用基本身份验证,而 IIS 使用 NTML。第一次尝试显然是将 IIS 的挑战方案更改为 NTLM,如下所示,但得到了相同的错误(我也已经为 restlet jar 添加了网络扩展)。
resource.setChallengeResponse(ChallengeScheme.HTTP_NTLM, userName, pwd);
另外,我认为有一种方法可以使用 Apache http 客户端 (NTCredentials) 类,但我仍然想使用 restlet jar 来避免对现有代码进行大量更改。
有什么建议吗?任何帮助,将不胜感激。 提前致谢。
【问题讨论】:
标签: java apache rest iis restlet