简体   繁体   English

UWP App无法通过摘要身份验证作为多部分/表单数据发布到Web服务

[英]UWP App fails to post to a web service as multipart/form-data with digest authentication

When trying to post to a web service as multipart/form-data with digest authentication. 尝试通过摘要身份验证作为多部分/表单数据发布到Web服务时。 It is failing with the following error 'System.Net.CredentialCache' is not supported for property 'Credentials'. 它失败,并出现以下错误“属性”不支持“ System.Net.CredentialCache”。

Using the below code to send credentials: 使用以下代码发送凭据:

HttpWebRequest httpWebRequest = WebRequest.Create(requestUrl) asHttpWebRequest;
string formDataBoundary = String.Format("----------{0:N}", Guid.NewGuid());
string contentType = "multipart/form-data; boundary=" + formDataBoundary;
byte[] formData = GetMultipartFormData(parameters, formDataBoundary);

if (httpWebRequest == null)
{
    thrownewNullReferenceException("request is not a http request");
}

// Set up the request properties. 
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = contentType;
httpWebRequest.CookieContainer = newCookieContainer();
var credentialCache = newCredentialCache();
credentialCache.Add(
    newUri("http://someurl.com"), // request url's host
    "Digest",  // authentication type 
    newNetworkCredential(username, password) // credentials 
);
httpWebRequest.Credentials = credentialCache;

We changed the services to use post with application/json instead and that solved it. 我们将服务更改为将post与application / json一起使用,从而解决了该问题。

var response = await httpClient.PostAsync(requestUrl, new StringContent(jsonString, Encoding.UTF8, "application/json")); var response = await httpClient.PostAsync(requestUrl,new StringContent(jsonString,Encoding.UTF8,“ application / json”));

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

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