简体   繁体   中英

Web Service 401: Unauthorized Error

I am running a web service locally that connects to an outside server that i do not have access to.

I keep receiving the "401: Unauthorized" error even though the test credentials are confirmed exactly correct by the admins of this web service.

Do i need to adjust any IIS settings?

Here is a screenshot of the error.

在此输入图像描述

        // Webservice
        IdentityService ws = new IdentityService();

        // Test Static Credentials
        string username = "twfnf";
        string password = "testme99";
        string domain = "testapps1";

        NetworkCredential credentials = new NetworkCredential(username, password, domain);

        CredentialCache credCache = new CredentialCache();
        credCache.Add(new Uri(ws.Url), "Basic", credentials);

        ws.Credentials = credCache;
        ws.PreAuthenticate = true;
        ws.AuthenticateUser();

Removing the following code with Basic Authentication, fixed the issue.

CredentialCache credCache = new CredentialCache();
credCache.Add(new Uri(ws.Url), "Basic", credentials);

Final Code Working:

    // Webservice
    IdentityService ws = new IdentityService();

    // Test Static Credentials
    string username = "twfnf";
    string password = "testme99";
    string domain = "testapps1";

    NetworkCredential credentials = new NetworkCredential(username, password, domain);

    ws.Credentials = credentials;
    ws.PreAuthenticate = true;
    ws.AuthenticateUser();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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