Pinch
Pinch

Reputation: 4207

WebAPI not working in Fiddler

I have created a POST WebApi that i can call as follows:

<script type="text/javascript">

var TheData = {
    Number: "7181112222",
    Username: "myusername",
    Password: "mypassword",
    enable: "True",
};

$.ajax({
    type: "POST",
    cache: "False",
    url: "http://www.######.com/someapi/api/SettingsConfig",
    data: TheData
}).done(function (msg) {
    alert(msg);
}).error(function (msg) {
    alert('Fail');
});

</script>

I will get an alert of 'Success' when i run this code.

When i run this code in fiddler...yipes!!

POST http://www.######.com/someapi/api/SettingsConfig Number=6464482035&Username=metheuser&Password=9999&enable=True

404 error

Why the inconsistancy!

Upvotes: 0

Views: 395

Answers (2)

Anatolii Gabuza
Anatolii Gabuza

Reputation: 6260

There's two possible reasons of such behavior:

  • Incorrect Content-Type which should be application/json value set;
  • Not enabled CORS on your API (in this case you're not allowed to call API from untrusted domains);

Upvotes: 0

Joanna Derks
Joanna Derks

Reputation: 4063

In the javascript snippet you're posting a JSON object, while in the fiddler example it's an x-www-form-urlencoded string.

Have you tried including the Content-Type header with your request:

  • application/x-www-form-urlencoded and posting the string
  • application/json and posting the JSON object

What does your controller's method signature look like - do you hit the method in the second example at all or is it erroring out before that?

What does 404 actually mean in this context - 'number' not found / post data null ?

Upvotes: 1

Related Questions