this is my service
[HttpPost]
public AgentMasterEntity AgentLogin([FromBody]string username)
{
AgentMasterEntity Agent = new AgentMasterEntity();
Agent = am.AgentLogin(username[0].ToString(),username[1].ToString());
return Agent;
}
this my jquery to call that sevice:
function testapi()
{
alert("enter");
var username = "santu";
var password = "hgf";
$.ajax({
type: "POST",
url:"http://localhost:1427/api/Agent/AgentLogin",
data:JSON.stringify([username,password]),
contentType: "application/json; charset=utf-8",
dataType: "text json",
success: function (resp) {
alert("ahi");
},
error: function (jqXHR, exception) {
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
alert(msg);
}
});
}
out5 put shows Internal Server error:
please help me im new to web api...
is my code wrong and how can i pass values frombody values