简体   繁体   English

IIS Windows身份验证错误(401.1)

[英]IIS windows authentication error (401.1)

I have configure IIS 8.0 with PHP 5.3 , along with SQL Server. 我已经将IIS 8.0与PHP 5.3以及SQL Server一起配置。

I am not sure what is going wrong. 我不确定出了什么问题。 I am able to see my JSON string in web browser , when I type in URL in the browser, 在浏览器中输入URL时,我可以在网络浏览器中看到JSON字符串,

But When I passed it to the code below, it is return me 但是当我将其传递给下面的代码时,它返回了我

IIS 8.0 Detailed Error - 401.2 - Unauthorized

401.2 Error page in my eclipse. 401.2错误页面在我的日食中。

I am connecting to the database via Windows Authentication. 我正在通过Windows身份验证连接到数据库。 Therefore , I have set Windows Authentication enabled in my IIS. 因此,我在IIS中设置了启用Windows身份验证。 I cannot able any other authentication other than Windows authentication , then my JSONstring is not return at all from the browser as well., in that case. 除了Windows身份验证之外,我无法进行其他任何身份验证,因此在这种情况下,我的JSONstring也完全不会从浏览器返回。

I have tried the solution mentioned in the below URL 我已经尝试了以下网址中提到的解决方案

http://support.microsoft.com/kb/942043

The problem still persists 问题仍然存在

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;

public class JSONTester {

    /**
     * @param args
     * @throws Exception 
     */
    public static void main(String[] args) 
    {
        InputStream is = null;
        String json = "";

        try 
        {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost("http://localhost/hive/get_all_products.php");
            httpPost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            System.out.println(e.toString());
        }
        System.out.println(json);
    }
}

Any help would be great . 任何帮助都会很棒。

Thanks !!! 谢谢 !!!

确保用于身份验证的帐户具有网站目录中文件的权限。

Internet Explorer is the only browser that does the NTLM authentication using integrated mode out-of-the-box, this is why your URL works in your 'browser'. Internet Explorer是唯一使用现成的集成模式进行NTLM身份验证的浏览器,这就是为什么您的URL在“浏览器”中可用的原因。 Your Java HttpClient must authenticate explicitly and answer the NTLM challenge from the server. 您的Java HttpClient必须显式进行身份验证,并应对来自服务器的NTLM挑战。 See HttpClient NTLM Authentication : 请参阅HttpClient NTLM身份验证

NTLM is the most complex of the authentication protocols supported by HttpClient. NTLM是HttpClient支持的最复杂的身份验证协议。 It is a proprietary protocol designed by Microsoft with no publicly available specification... NTLM authentication requires an instance of NTCredentials be available for the domain name of the server or the default credentials. 它是Microsoft设计的专有协议,没有公开可用的规范... NTLM身份验证要求NTCredentials实例可用于服务器的域名或默认凭据。 Note that since NTLM does not use the notion of realms HttpClient uses the domain name of the server as the name of the realm. 请注意,由于NTLM不使用领域的概念,因此HttpClient使用服务器的域名作为领域的名称。 Also note that the username provided to the NTCredentials should not be prefixed with the domain - ie: "adrian" is correct whereas "DOMAIN\\adrian" is not correct... 还要注意,提供给NTCredentials的用户名不应以域开头-即:“ adrian”是正确的,而“ DOMAIN \\ adrian”是不正确的...
HttpClient provides limited support for what is known as NTLMv1, the early version of the NTLM protocol. HttpClient对NTLMv1(NTLM协议的早期版本)提供了有限的支持。 HttpClient does not support NTLMv2 at all . HttpClient完全不支持NTLMv2

The important thing to take home is that HttpClient does not support integrated authentication. 带回家的重要一点是,HttpClient的支持集成身份验证。 You must provide explicit credentials, which makes it always probe to bad practices because of the requirement to provide the account password explicitly. 您必须提供明确的凭据,由于要求明确提供帐户密码,因此它始终会探查不良做法。 Make sure you do not store it but ask it from the user, much the same way Firefox does when visiting a site that requests an NTLM challenge. 确保您不存储它,而是向用户询问它,这与Firefox在访问请求NTLM挑战的站点时所采用的方法相同。

Read The NTLM Authentication Protocol and Security Support Provider for more details. 阅读NTLM身份验证协议和安全支持提供程序以获取更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM