0

I am trying to access a 3rd party API. The documentation of the 3rd party API provider has given the following PHP code on how to access the data sent. My code is written in C# dotnetcore. I have tried several ways to access the API but I get a Error 415. Can someone help me resolve this.

<?php

    $mmid         = $_POST['mm_id'];
    $ooid             = $_POST['oo_id'];

?>

My C# Code

    [HttpPost("b_notice")]
    [ProducesResponseType(typeof(string), (int)HttpStatusCode.OK)]
    public async Task<ActionResult> APIUrl(string mm_id)
    {
        try
        {
            return Ok(mm_id);
        }
        catch (Exception ex)
        {
            return BadRequest(ex.Message);
        }

    }

The response code I get is 415 Unsupported Media Type. . I think they don;t use JSON. Can someone help me resolve this ?

Note: The 3rd party provider says they use 'application/x-www-form-urlencoded.

1 Answer 1

1

You should be able to accomplish this by setting the Content-Type response header. The API is expecting input from an html form but it's getting input from somewhere it doesn't expect. I'm not sure how you would go about changing the headers in C# but that's a good place to start. Try testing it out in an http request debugger like postman

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

2 Comments

This is what I did ` [Consumes("application/x-www-form-urlencoded")] `.
Did that work? The word Consumes makes me think it's modifying the Accept header which is meant to represent the type of data of the response back from the server.

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.