jquery - Web API OWIN receives null data from $.AJAX POST withCredentials:true -


i'm calling web api hosted on windows service via owin, jquery ajax post asp.net mvc application (posting data via 'data' option). working until decided add integrated windows authentication. added xhrfields: { withcredentials: true } $.ajax call complete client side of authentication. data returned null.

here server side startup:

public class startup {     public void configuration(iappbuilder appbuilder)     {         var config = new httpconfiguration();          var listener =             (httplistener)appbuilder.properties["system.net.httplistener"];         listener.authenticationschemes = authenticationschemes.integratedwindowsauthentication;          //maps http routes based on attributes         config.maphttpattributeroutes();         config.filters.add(new authorizeattribute());          //enable webapi         var cors = new enablecorsattribute("*", "*", "*");         cors.supportscredentials = true;         config.enablecors(cors);          appbuilder.usewebapi(config);     } } 

here web api method:

public httpresponsemessage postsomething([frombody]string datain)

fyi, string can large passed on uri.

here $.ajax call:

    function testajax() {         $.ajax({             url: 'http://localhost:8080/api/test/postsomething',             xhrfields: { withcredentials: true },             type: 'post',             data: 'test'         }).done(function (response) {             alert(response);         });     } 

datain null.

well found answer, simple still don't know details behind scenes why works. modifying "data: 'test'" "data: {'': 'test'}".

function testajax() {     $.ajax({         url: 'http://localhost:8080/api/test/postsomething',         xhrfields: { withcredentials: true },         type: 'post',         data: { '': 'test' }     }).done(function (response) {         alert(response);     }); } 

if knows why, please post reply. thanks!


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -