Search code examples
c#xamarinportable-class-libraryhockeyapp

404 error when trying to upload crash to hockeyapp


I'm trying to upload crash manually to HockeyApp using public API. When calling the api link using Postman and uploading crash.log file it works fine but when I try to do the same from C# code I get 404 error.

Here is my code:

string log = ""; //log content
using (HttpClient client = new HttpClient())
{
    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("*/*"));

    var content = new MultipartFormDataContent();

    var stringContent = new StringContent(log);
    stringContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain");

    content.Add(stringContent, "log", "crash.log");

    var response = await this.client.PostAsync("https://rink.hockeyapp.net/api/2/apps/[APP_ID]/crashes/upload", content);
}

I was using WireShark to analyse the request that Postman is sending and tried to make mine look exactly the same. The only difference I see is that request from C# code has filename* field in Content-Disposition for the attachment while the one from Postman doesn't:

Content-Disposition: form-data; name="log"; filename="crash.log"; filename*=utf-8''%22crash.log%22

It might be worth mentioning that the code is written in portable library in Xamarin project.


Solution

  • Following @Lukas Spieß sugestion I asked the question on HockeyApp support. Apparently they don't handle quotes in the boundary header. The one thing I missed comparing Postman request and mine.

    Here is the solution:

    var contentTypeString = content.Headers.ContentType.ToString().Replace("\"", "");
    
    content.Headers.Remove("Content-Type");
    content.Headers.TryAddWithoutValidation("Content-Type", contentTypeString);