2

I'm hoping to pass a URI string into a GET method in my APIController inhering class. I've tried putting it in the Content as raw text, and as a string param without luck. I've made a model to pass in as a param:

namespace ServerDock.Models.Web
{
    using System.Runtime.Serialization;

    [DataContract]
    public partial class UriWeb
    {
        [DataMember]
        public string Uri_String { get; set; }

        public UriWeb() { }

    }
}

Now my Controller's function is as follows:

[Route("file", Name = "Download")]
[HttpGet]
public async Task<IHttpActionResult> DownloadFile([FromBody] UriWeb uri)

With a Postman call whos JSON body is as follows:

{
    "Uri_String":"https://mysite.windows.net/files/ec0a30c8-265d-4c94-b176-387004f5f566-.jpg"
}

My breakpoint in the controller function is never hit, and I get the error: The request body is incomplete.

Any idea what I'm doing wrong?

0

1 Answer 1

1

Change [HttpGet] to [HttpPost]. GET's can't have a [FromBody] parameter:

[Route("file")]
[HttpPost]
public async Task<IHttpActionResult> DownloadFile([FromBody] UriWeb uri){...}

If you have to use GET, then you need to pass it as a Query String. So you would change it to:

[Route("file")]
[HttpGet]
public async Task<IHttpActionResult> DownloadFile([FromQuery] Uri uri){...}

And then call it as so (query string has been encoded):

http://example.com/api/file?uri=http%3A%2F%2Fexample.com%2Ffile.zip
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.