79609733

Date: 2025-05-07 03:00:09
Score: 0.5
Natty:
Report link

Finally figured it out. @Vijay's comment gave me an insight where the issue may be. The solution was in the way the request was getting posted. By default, I had the request headers default to 'multipart form data'.

I had to update the post request function to have parameterized contenttype value:

public [return] DoPostRequest([param1], [param2], ContentTypes contentType)
{
    ...
    [httpclient].DefaultRequestHeaders.Add("ContentType", contentType.ToString());
    ...
}

where: ContentTypes is

public class ContentTypes
{
    public static readonly ContentTypes Name = new("ContentType");
    public static readonly ContentTypes JSON = new("application/json");
    public static readonly ContentTypes XML = new("application/xml");
    public static readonly ContentTypes TEXT = new("text/plain");
    public static readonly ContentTypes HTML = new("text/html");
    public static readonly ContentTypes FORM_URLENCODED = new("application/x-www-form-urlencoded");
    public static readonly ContentTypes MULTIPART_FORM_DATA = new("multipart/form-data");

    public string Value { get; }

    private ContentTypes(string value) => Value = value;

    public ContentTypes()
    {
    }

    public override string ToString() => Value;
}
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Vijay's
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: the.herbert