Avatar of Tom Knowlton
Tom Knowlton
Flag for United States of America asked on

What URL will cause this "POST" method to fire?

//What URL will cause this "POST" method to fire?


namespace UrlShortenerApp.Controllers
{
    [Route("api/[controller]")]     [ApiController]     public class ShortenUrlController : ControllerBase     {         [HttpPost]         public string Post([FromBody] string url)         {             return string.Format("TODO: Call 3rd party URL Shortening API to shorten '{0}'", url);         }     } }

Open in new window

.NET MVC.NET Programming* asp.net core mvcASP.NET

Avatar of undefined
Last Comment
Chinmay Patel

8/22/2022 - Mon
Ryan Chong

try such as:

http(s)://yourDomain/anyMapping/api/ShortenUrl

Open in new window

Chinmay Patel

As this is a POST request, you will need some code or a tool (Postman as in above example) to call this API. If it was a GET request, you could directly fire it by navigating to a particular URL.
it_saige

As Chinmay states, calling a route from a web browser directly is always GET.  In order to use any other HTTP method (POST, PUT, PATCH or DELETE) you would have to use a tool (like Postman as shown by Ryan) or code in a program/script.

-saige-
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Tom Knowlton

ASKER

Tom Knowlton

ASKER
Ryan:

What authorization are you using, and what do your headers look like?  Do you have a way to eport your POSTMAN settings, minus any info you do not want to expose?
Ryan Chong

for your error, try select body as "Raw" and type as "JSON"

I was using the same codes you provided and manage to test locally.
What authorization are you using, and what do your headers look like?
Well, for my case just some Basic Auth, which could be different in your case (it may not be necessary if you didn't configure this part).

For the header, nothing much to customize here.

to prove what I'm saying here, here are the screenshots


⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Tom Knowlton

ASKER
Ryan:

I believe you.  I am only trying to figure-out what I am doing wrong.

Tom


it_saige

Also your POST method uses the Body instead of the URL for parameters.

-saige-
Tom Knowlton

ASKER
saige:

I am supposed to use the URL?

Or am I supposed to use the BODY?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
it_saige

If you are specifying a JSON object it would look like this:
{ "url": "http://www.yahoo.com" }

Open in new window

HTH,

-saige-
it_saige

Use the Body as specified by Ryan with a raw JSON object as I specified above.

-saige-
Tom Knowlton

ASKER
Still says "404 not found"

But the server is recording my attempts to connect:


⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Tom Knowlton

ASKER
Still says "404 Not Found":

{ "url": "http://www.yahoo.com" }

Open in new window



it_saige

Can you provide more detail about the configuration of your API (global.asax, etc)?

-saige-
Ryan Chong

are you running your .NET project with IIS Express? if yes, make sure start the debugging ("Run") before consume the API.

OR to make it easier, try to setup a website for your project in IIS instead.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Tom Knowlton

ASKER
I don't know about a global.asax file:

This is a programming test I am taking.  But for right now I am trying to get the POST method to fire.




IIS:

It looks like "localhost" is able to run (the default page):