1

I received the following error when downloading from Box server:

    InnerException  {System.ArgumentException: [net_WebHeaderInvalidControlChars]
Arguments: 
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.7.60408.0&File=System.Net.dll&Key=net_WebHeaderInvalidControlChars
Parameter name: name
   at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState)
   at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState)}  System.Exception {System.ArgumentException}

Shown below is the code snippet.

using (HttpClient client = new HttpClient(handler) { MaxResponseContentBufferSize = Int32.MaxValue })
{
    client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);

    try
    {
        var fileResponse = await client.GetAsync(requestUrl, HttpCompletionOption.ResponseHeadersRead);                    

        if (fileResponse != null && fileResponse.StatusCode == System.Net.HttpStatusCode.OK)
            return await fileResponse.Content.ReadAsByteArrayAsync();
        else return null;
    }
    catch(Exception e)
    {
        System.Diagnostics.Debug.WriteLine("Error in getAsync, " + e.StackTrace);                    
        return null;
    }

}

Note that this only happens for files with Korean (non-English) filenames and corrupted files. For image files and non-corrupted files, I was able to download successfully. (Example of corrupted file is a word or ppt file that shows an error msg when opened).

TZHX
  • 5,291
  • 15
  • 47
  • 56
kcire
  • 11
  • 1

1 Answers1

0

Having the same issue in windows phone 8. I tried HttpResponseMessage response = await httpClient.SendAsync(requestMessage);

I tried WebClient client = new WebClient(); client.OpenReadAsync(new Uri(url,UriKind.RelativeOrAbsolute));

I tried IRestResponse from RestClient

All resulting in exception with empty value and inner exception net_WebHeaderInvalidControlChars.

The problem was that the user agent passed from windows client was not recognized server side. As a result, one from the returned response headers, was making .Net to crash in a lower level and the response could not be processed.

Adding NativeHost as the recognized UserAgent fixed the exception

Byron Gavras
  • 970
  • 10
  • 16