gpt4 book ai didi

coldfusion - 将 Apache HttpComponents 用于具有 NTLM 身份验证的 http 请求

转载 作者:行者123 更新时间:2023-12-02 04:05:20 25 4
gpt4 key购买 nike

快速背景。

CFHTTP 不支持 Windows NTLM/Authenticate 身份验证,仅支持基本身份验证。我需要发出必须针对 NTLM 进行身份验证的 http 请求,因此我最终推出了自己的 CFHTTP 版本。

我找到了Terry Ryan's article它使用 apache httpclient 3.1 版执行摘要身份验证,并在此基础上使用 4.1.2 版而不是包括 NTLM 功能。

我有一个函数将执行一个 get 请求,然后是其他函数来处理返回一个看起来像 cfhttp 结果集的结构。我所做的更改是基于 authentication tutorial example .

public any function httpRequest(url,username,password,domain) {
var httpClient = createObject("java","org.apache.http.impl.client.DefaultHttpClient");
var authScope = createObject("java","org.apache.http.auth.AuthScope");
var httpCredentials = createObject("java","org.apache.http.auth.NTCredentials");
var httpGet = createObject("java","org.apache.http.client.methods.HttpGet");
var jURL = createObject("java", "java.net.URL").init(arguments.url);
var host = jURL.getHost();
var path = jURL.getPath();
var httpHostTarget = createObject("java","org.apache.http.HttpHost").init(host,80,"http");
var localContext = createObject("java","org.apache.http.protocol.BasicHttpContext");
var httpContent = {};
var response = '';

if (len(arguments.username) and len(arguments.password) gt 0){
httpCredentials.init(arguments.Username, arguments.password, cgi.remote_host,arguments.domain);
httpClient.getCredentialsProvider().setCredentials(authScope.ANY, httpCredentials);
}

if (!Len(path)) path = "/";
httpGet.init(path);

response = httpClient.execute(httpHostTarget, httpget, localContext);

httpContent = convertHttpClientResponseToCFHTTPFormat(response);

httpClient.getConnectionManager().shutdown();

return httpContent;
}

在我更改功能以执行身份验证之前,这一切正常。

不幸的是,我现在得到:

The execute method was not found.

Either there are no methods with the specified method name and argument types or the execute method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 2 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.



据我所知,HttpClient 中只有一个匹配的 execute() 函数用于传递给它的对象类,所以我有点困惑。 JavaCast 不允许您强制转换为复杂对象或父类(super class)型,因此这不起作用。

谁能建议我如何让它工作?如何减少歧义?

最佳答案

查看错误,在具有相同数量参数的两个执行方法之间感到困惑。虽然不知道为什么...

无论如何,我找到了解决错误的方法。它涉及将您所追求的方法拉出类并直接调用它。如果 ColdFusion 对转换 Java 对象更满意,那么生活可能会更轻松。

//response = httpClient.execute(httpHostTarget, httpget, localContext);

classes = [httpHostTarget.getClass(), CreateObject('java', 'org.apache.http.HttpRequest').getClass(), CreateObject('java', 'org.apache.http.protocol.HttpContext').getClass()];
method = httpClient.getClass().getMethod('execute', classes);
params = [httpHostTarget, httpget, localContext];
response = method.invoke(httpClient, params);

可能有另一种方法可以做到这一点(而不是类型转换),但这就是我所拥有的;)

关于coldfusion - 将 Apache HttpComponents 用于具有 NTLM 身份验证的 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7979208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com