1

I am executing a post method in my API using fiddler I get error "A callback parameter was not provided in the request URI.". However, this works for get method.

I have seen several answers to this question, and as per the error I need to specify a callback parameter. However, I'm not sure how to do this using fiddler.

In response to one of those answers from Can I make a jQuery JSONP request without adding the '?callback=' parameter in URL? . I've tried the following in fiddler and I get the same error..

url: http://velopoint-api.localhost.dev/api/v1/tasks?callback=foo

header:

User-Agent: Fiddler
Host: velopoint-api.localhost.dev
ContentType: application/json; charset=utf-8
Authorization: basic "UNQUOTED"
Content-Length: 47
jsonp: true
jsonpCallback: jsonCallback
dataType: jsonp

request body

{ "Title":"New Task", "DueDate":"20-jul-2014" }

Startup

        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.

            // Change Formater to use CamelCasePropertyNamesContractResolver

            var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().FirstOrDefault();
            jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            /* Support JsonP */
            //register JSONP media type formatter
            config.Formatters.Insert(0, new JsonpMediaTypeFormatter(jsonFormatter));

            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize;
            config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
            ...
}
Community
  • 1
  • 1
Dave Russell
  • 141
  • 1
  • 8

1 Answers1

1

After playing around a little, I've finally figured it wasn't actually routing to the post method.

My header is now

User-Agent: Fiddler
Host: velopoint-api.localhost.dev
Authorization: basic UNQUOTED
Content-Length: 224
Content-Type: application/json

I fixed the problem by specifying Route attribute to my Post method and passing an empty string to the pattern parameter, both on the Get and the Post (as I already have the RoutePrefix attribute specified on the class.

[RoutePrefix("api/v1/tasks")]
[VeloPointAuthorise(perUser: true)]
public class TaskController : BaseApiController
{

    [HttpGet]
    [Route(template:"", Name = "TaskRoute")]
    public HttpResponseMessage Get(int page = 0)
    {
       ....
    }

    [HttpPost]
    [Route(template:"")]
    public HttpResponseMessage Post([FromBody] OrganiserTaskModel model)
    {
       ....        
    }
Dave Russell
  • 141
  • 1
  • 8