Reputation: 4207
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
Why the inconsistancy!
Upvotes: 0
Views: 395
Reputation: 6260
There's two possible reasons of such behavior:
Content-Type
which should be application/json
value set; Upvotes: 0
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 stringapplication/json
and posting the JSON objectWhat 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