Javascript 如何从浏览器接收到.NET 4.5 C的请求#
我在工作中继承了一些代码,这些代码似乎只能获取第一个参数。如果我尝试添加一个JSON对象,它似乎不会被理解。前端是用Ext.js编写的,后端是C#NET 4.5 浏览器代码:Javascript 如何从浏览器接收到.NET 4.5 C的请求#,javascript,c#,.net,extjs,Javascript,C#,.net,Extjs,我在工作中继承了一些代码,这些代码似乎只能获取第一个参数。如果我尝试添加一个JSON对象,它似乎不会被理解。前端是用Ext.js编写的,后端是C#NET 4.5 浏览器代码: frame.onload = WorkManager.util.DownloadPrint.Unmask(); var form = Ext.get('iframeForm'); if (form == null) { form =
frame.onload = WorkManager.util.DownloadPrint.Unmask();
var form = Ext.get('iframeForm');
if (form == null) {
form = body.createChild({
tag: 'form',
cls: 'x-hidden',
id: 'iframeForm',
name: 'iframeForm',
standardSubmit: true,
method: 'POST',
//action: webroot + 'dispatch.aspx',
action: AppSettings.root + '/Download/GetExcelData/' + reqType,
params: {'startDate': 'test', 'endDate':'anothertest'},
target: 'downloadIframe'
});
和后端代码:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Http;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Fcx.Fu.Tast.DBAccess.E2EUI;
using Newtonsoft.Json.Linq;
namespace Fcx.Fu.Tast.Xtra.WebApi.Controllers.E2Z
{
//public class Dates { string startDate{get; set;} string endDate{get; set;}}
public class DownloadController : XtraBaseController
{
[AcceptVerbs("GET", "POST")]
public HttpResponseMessage GetExcelData(String id, JObject data)
{
switch (id)
{
case "xeDownload":
return GetExceptionData(id);
case "xaeDownload":
return GetAssetExceptionData(id);
case "oobDownload":
return GetOOBExceptionData(id);
case "techShortDownload":
return GetTechShortExceptionData(id);
}
return null;
}
“id”输入正确,但HttpResponseMessage中的Json数据参数为空…将数据参数作为Json发送。您当前发送的endDate未映射到方法的参数
params: {'startDate': 'test', data: { 'property1': 'value1', 'property2': 'value2', 'property3': { 'p3property1': 'p3value1' } },
如果您使用的是Chrome,您可以查看网络选项卡并查看请求头,看看它是否符合API端点的期望。尝试使用fiddler或postman之类的工具自己向端点发出POST请求。那就从那里开始吧