Search code examples
c#windows-store-appswin-universal-appwinrt-xamlwindows-10-mobile

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. It is failing with the following error 'System.Net.CredentialCache' is not supported for property 'Credentials'.

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;

Solution

  • We changed the services to use post with application/json instead and that solved it.

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