JSON オブジェクト Prueba を受信する Web サービスがあります。
public class Prueba
{
public string valor1 { get; set; }
public string valor2 { get; set; }
}
public JsonResult Pruebas(Prueba item)
{
string metodo = Request.HttpMethod;
return Json("error", JsonRequestBehavior.AllowGet);
}
そして、JQuery を使用して Web サービスを呼び出したい:
$.ajax({
type: 'Post',
dataType: 'json',
url: 'http://localhost:24780/Api/Pruebas',
data:'{"valor1":"a","valor2":"b"}',
contentType: 'application/json; charset=utf-8',
success: function (data) {
console.debug(data);
},
error: function (data) {
console.debug(data);
}
});
問題は、Request.method が POST ではなく OPTION の値を取ることです。また、オブジェクトの値は null です。
問題なく SOAP UI を使用して Web サービスをテストしましたが、JQuery で動作しない理由がわかりません。