3

メールアドレスを渡すために、タイプとして POST で ajax を使用しています。

$.ajax({
    url: "api/Search/UserByEmail",
    type: "POST",
    data: JSON.stringify({ emailAddress: userEmail }),
    contentType: "application/json;charset=utf-8",
    dataType: "json",
    success: function (data) { ... }
});

コントローラ:

[HttpPost]
public IEnumerable<Object> UserByEmail([FromBody] string emailAddress) { ... }

それがフィドラーの言うことです:

POST http://localhost:52498/api/Search/UserByEmail HTTP/1.1
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: application/json;charset=utf-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:52498/#
Accept-Language: de-DE
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Host: localhost:52498
Content-Length: 35
DNT: 1
Connection: Keep-Alive
Pragma: no-cache

{"emailAddress":"mail@example.com"}

emailAddress パラメータが常に null なのはなぜですか?

4

3 に答える 3

0

への元の ajax 呼び出しのデータ プロパティを変更します。

data: '"' + userEmail + '"',

これらの Web API 呼び出しの一部を機能させるには、少し注意が必要な場合があります

于 2015-01-08T18:47:49.673 に答える