首先,我已经阅读并尝试了所有相似的主题,但它并没有解决我的问题。 我有和Angularjs应用程序对c#后端进行api调用。
我的应用程序的工厂部分看起来像这样
return $http({
url: url,
method: "POST",
headers: { 'Content-Type': 'application/json' },
data: {
bookedDate: customer.choiceDate,
bookedTime: customer.choiceTime,
couponCode: customer.couponcode,
firstName: customer.firstName,
lastName: customer.lastName,
userName: customer.choiceName,
emailAddress: customer.emailAddress,
phoneNumber: customer.choicePhoneNumber,
customerAddress: customer.choiceAddress,
food: customer.Food,
merchantName: customer.merchantName,
merchantEmailAddress: customer.merchantEmailAddress,
merchantOfficeAddress: customer.merchantOfficeAddress,
merchantPhoneNumber: customer.merchantPhoneNumber
}
});
,控制器方法如下所示
[System.Web.Http.HttpPost]
public bool Post(BookingDto customer)
{
bool status = false;
return status;
}
现在web.config文件如下所示:
<handlers accessPolicy="Read, Script">
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"
path="*."
verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
modules="IsapiModule"
scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
preCondition="classicMode,runtimeVersionv4.0,bitness64"
responseBufferLimit="0" />
</handlers>
<modules>
<remove name="WebDAVModule"/>
</modules>
这适用于fiddler和Angularjs应用程序上的POST API调用,但是当我执行PUT时,它们都会失败。 我研究了这个,然后添加
<modules runAllManagedModulesForAllRequests="true" />
然后PUT和POST都在fiddler上工作,但是它们都不适用于Angularjs部分。 最后当我将Angularjs的Content-Type更改为
时headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
我从Angularjs得到了一个200 ok的POST响应,但它没有达到调试器断点但是如果我删除了Angularjs请求的数据部分,即
data: {
bookedDate: customer.choiceDate,
bookedTime: customer.choiceTime,
couponCode: customer.couponcode,
firstName: customer.firstName,
lastName: customer.lastName,
userName: customer.choiceName,
emailAddress: customer.emailAddress,
phoneNumber: customer.choicePhoneNumber,
customerAddress: customer.choiceAddress,
food: customer.Food,
merchantName: customer.merchantName,
merchantEmailAddress: customer.merchantEmailAddress,
merchantOfficeAddress: customer.merchantOfficeAddress,
merchantPhoneNumber: customer.merchantPhoneNumber
}
它命中调试器的断点。
请有人帮我解决这个问题吗? 感谢。