0

We have a Web API (MVC4) application that returns images from the database. I have verified that the call to the Web API does produce a valid image.

Here is the Fiddler result showing that the image is returned properly: Fiddler API Call:

I tried setting an image element with the same source as the call, but that didn't work:

<img id="img" src="http://localhost/Seek/api/artifactcontent/?userName=XXXXX&password=XXXXXX&id=15-00931-27" /> 

What am I doing wrong?

1 Answer 1

2

You request in Fiddler is a POST request; the <img> tag sends a GET request. If you want to display images using <img> tags, you'll need to make your action accept GET requests instead of (or in addition to) POST.

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

3 Comments

OK great! Can I make the same Post action accept Get, or do I need to create another action called Get and have both actions call the function that returns the image?
The same action can accept both verbs - you can use the [AcceptVerbs] attribute: [AcceptVerbs("GET", "POST")]
Yes, [AcceptVerbs] work, as long as you have routes which can map to the action with that attribute.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.