ASP.net 请求发布的表单数据始终为空

本文关键字:数据 表单 net 请求 ASP | 更新日期: 2023-09-27 18:32:50

以下Javascipt:

$.ajax({
    type: "POST",
    data: "langID=" + viewingLangID + "&currency=" + newVal + "&basePrices=" + pricePostData,
    dataType: "json",
    url: "/handlers/payments/getconversions.ashx",
    success: function(data) {

生成以下 HTTP 请求:

General
Request URL:https://127.0.0.1:3333/handlers/payments/getconversions.ashx
Request Method:POST
Status Code:200 OK
Remote Address:127.0.0.1:3333
Response Headers
Cache-Control:private
Content-Length:78
Content-Type:application/json; charset=utf-8
Date:Mon, 01 Feb 2016 17:35:41 GMT
Server:Microsoft-IIS/8.5
X-AspNet-Version:4.0.30319
X-MiniProfiler-Ids:["9d45ff72-2efa-4d31-a5c7-c109573699c6"]
X-Powered-By:ASP.NET
Request Headers
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Category:application/x-www-form-urlencoded; charset=UTF-8
Content-Length:62
Content-Type:text/plain;charset=UTF-8
Cookie:C3_Login=ID=e99af6ee-b0fc-4d92-89f6-262d37d7a2b0&Key=BAFKzQhxZsknMyE1bvbjsFouDvaZUSxVzP0oGmN8kONCJRUR1z; _gat=1; _ga=GA1.1.1302222369.1453808296; C3_Currency=GBP
Host:127.0.0.1:3333
Origin:https://127.0.0.1:3333
Referer:https://127.0.0.1:3333/?p=ContentIndividuals
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payload
langID=2&currency=GBP&basePrices=299,799,2499,9999,10999,13999

但是,如果我这样做getconversions.ashx

context.Request.Form["currency"]

该值始终null 。 知道为什么会这样吗? 我已经尝试过请求["货币"]和Request.Params["currency"]但它总是返回null

如果我记录上下文。Request.ServerVariables["ALL_RAW"]

Connection: keep-alive
Content-Length: 62
Content-Type: text/plain;charset=UTF-8
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: C3_Login=ID=e99af6ee-b0fc-4d92-89f6-262d37d7a2b0&Key=BAFKzQhxZsknMyE1bvbjsFouDvaZUSxVzP0oGmN8kONCJRUR1z; _gat=1; _ga=GA1.1.1302222369.1453808296; C3_Currency=GBP
Host: 127.0.0.1:3333
Referer: https://127.0.0.1:3333/?p=ContentIndividuals
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36
Content-Category: application/x-www-form-urlencoded; charset=UTF-8
Origin: https://127.0.0.1:3333
X-Requested-With: XMLHttpRequest

ASP.net 请求发布的表单数据始终为空

尝试将数据转换为对象。目前数据不是 json 格式。

var jsonData = {'langID':viewingLangID, 'currency':newVal, 'basePrices':pricePostData}
$.ajax({
    type: "POST",
    data: jsonData,
    dataType: "json",
    url: "/handlers/payments/getconversions.ashx",
    success: function(data) {

另请注意,pricePostData的值应该是 json [123,234,456,567]等的数组。

希望这有帮助