我正在开发UWP-App。因此,我创建了一个具有Windows身份验证的PUT-Webservice。
首先,我尝试使用以下代码进行调用:
JPasswordChangeData jPasswordChangeData = new JPasswordChangeData()
{
OldPassword = oldpassword,
NewPassword = newpassword
};
var credential = new NetworkCredential("<username>", "<password>", "<domain>");
string apiServerSecurePath = "https://MyServername:6501/";
var myCache = new CredentialCache();
// Add the target Uri to the CredentialCache with credential object
myCache.Add(new Uri(apiServerSecurePath), "NTLM", executingCredentials);
// Create an HttpClientHandler to add some settings
var handler = new HttpClientHandler();
handler.AllowAutoRedirect = true;
handler.Credentials = myCache;
HttpClient httpClient = new HttpClient(handler);
HttpResponseMessage httpResponseMessage = httpClient
.PutAsync(apiServerSecurePath + "api/ActiveDirectory/ChangePassword/" + username,
new StringContent(JsonConvert.SerializeObject(jPasswordChangeData), Encoding.UTF8, "application/json")).Result;
但是然后我得到了错误:
The value 'System.Net.CredentialCache' is not supported for property 'Credentials'.
下一步,我尝试使用“ Windows.Web.Http.HttpClient”:
var filter = new HttpBaseProtocolFilter();
filter.AllowAutoRedirect = true;
filter.ServerCredential = new PasswordCredential("<Domain>", "<username>", "<password>");
filter.AllowUI = false;
JPasswordChangeData jPasswordChangeData = new JPasswordChangeData()
{
OldPassword = oldpassword,
NewPassword = newpassword
};
Windows.Web.Http.HttpClient windowsHttpClient = new Windows.Web.Http.HttpClient(filter);
//HttpClient httpClient = new HttpClient();
var httpResponseMessage = await windowsHttpClient.PutAsync(
new Uri("http://MyDomain:6001/api/ActiveDirectory/ChangePassword/" + txtblk_samaccountname.Text.Trim()),
new HttpStringContent(JsonConvert.SerializeObject(jPasswordChangeData), Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json"));
我还在Package.appxmanifest中设置了所需的功能。
对不起,我只有德语的屏幕截图。这是翻译:
翻译后的意思是:
401-未经授权:由于凭据无效而拒绝访问。
给定的凭据未授权您查看此目录或页面。
有人知道我的失败是什么吗?
向前推你!
最好的问候
Matthias
答案 0 :(得分:0)
现在我知道更多了,但是我没有解决方案...
我没有说过UWP是为具有Windows 10 IOT Core的树莓开发的。
当我尝试从域中的PC发送凭据时,它会起作用。
当我在覆盆子上尝试相同的代码时,它不起作用。
我认为原因是reaspberry不在领域内。但是我无法将Windows 10 IOT Core加入域。只有Windows 10 IOT Enterprise可以加入域。但是Windows 10 IOT Enterprise无法安装在树莓上。
因此,我认为我必须在Web服务中添加基本身份验证。如果有人知道如何使用活动目录用户的凭据,我将非常感谢!