Net Web Api - How to Pass a Url as Input Parameter on a Get

I am trying to pass a URL as a input parameter to a ApiController from an Angular REST call. The URL comes as a query string (this is a Provider Hosted app in SharePoint, I need the URL to query SP FWIW).

Here is the method signature in the ApiController:

// GET: api/ProjectSite/5
public IEnumerable<ProjectSite> Get(string id)
{
    return ProjectSite.GetAllProjectSites(id);
}

And here is where I am making the call in Angular:

var spUrl = "'" + getParameterByName("SPHostUrl") + "'";

var queryUrl = "/api/ProjectSite/" + encodeURIComponent(spUrl);
return $http.get(queryUrl);

This generates a GET request that looks like this:

When I do I get 'HTTP 400 (Bad Request)' back. If I stop on a break point in the Angular code and change the input param to a simple string (e.g. 'asdf') the REST call is made and I see the Api is called. If I do not change the string and put a breakpoint inside the Get Api method the breakpoint is not reached, indicating that the code is blowing up somewhere in the route engine.

What I don't get is, while its encoded, the string I am trying to pass in should still be treated as a string, right? I also tried changing the input to Uri but that doesn't appear to work (and Uri isn't listed as a supported input type, anyways).

Anyone know how to pass a URL as input parameter?

1 Answer

Have you tried calling it using a query string?

var queryUrl = "/api/ProjectSite?id=" + encodeURIComponent(spUrl);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest