1

Not sure what I'm doing wrong here.

Trying to post a Base64 encoded byte array, and getting a 404.

The thing is, when I try it with a normal value ("test"), it works.

API:

[HttpPost]
public IHttpActionResult Post(dynamic data)
{
  // ...
  return Ok();
}

Client:

public static bool UploadDocument(string base64Image)
{
  // ...
  using (var handler = new HttpClientHandler() { UseDefaultCredentials = true})
  using (var client = new HttpClient(handler))
  {
    var data = new { Image = base64Image }; // Image = 123 (or any random value) Works.
    var res = client.PostAsJsonAsync(@"(url)", data).Result;
    if(res.IsSuccessStatusCode)
      // ...
  }
}

Tried a couple other variations, also tried using WebRequest instead. The issue remains.

8
  • Presumably youre expecting PostAsJsonAsnc to serialise the image to base 64. Is that definitely happening? What happens if you manually encode the image object as base 64, then attempt to post it? Commented Apr 19, 2017 at 9:14
  • 1
    @richzilla I'm already encoding it myself. Commented Apr 19, 2017 at 9:18
  • On closer inspection, yes you are... Commented Apr 19, 2017 at 9:21
  • Have you tried adding Content-Transfer-Encoding header. example httpclient.DefaultRequestHeaders.TransferEncoding.Add(new TransferCodingHeaderValue("BASE64")); w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html Commented Apr 19, 2017 at 9:22
  • Is it just that particular base 64 string thats causing problems? Can you base 64 encode the word 'test' and see if that goes through? Commented Apr 19, 2017 at 9:25

1 Answer 1

1

The size of the data I was trying to send was larger than the default maximum.

The 404 I got was actually 404.13, which is "Content Length Too Large".

You can find more about this here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.