0
从MVC控制器调用的Web API POST方法返回下面的错误:调用Web API Post方法错误“远程服务器返回错误:(405)不允许的方法”
"The remote server returned an error: (405) Method Not Allowed"
下面MVC控制器动作代码调用一个辅助类的方法和在调试时,我可以看到控制移动从这里到下一个方法:
public ActionResult Submit(FormCollection form)
{
Lead_Options lead = new Lead_Options();
lead.Situation = form.GetValue("InsuranceFor").AttemptedValue;
lead.State = form.GetValue("InsuranceState").AttemptedValue;
Uri url= Url_Helper.GetUri(BaseUrl, service1+"Post"); // returns http://localhost:52985/api/HealthInsurance/Post
string obj= new JavaScriptSerializer().Serialize(lead);
Object data = WebApi_Helper.PostData(url,obj);
return RedirectToAction("Parameters");
}
“WebApi_Helper.PostData”的Helper类,被起诉的通用方法来调用Web API:
public static string PostData(Uri url,string obj)
{
string data = null;
try
{
using (WebClient proxy = new WebClient())
{
proxy.Headers.Add(HttpRequestHeader.Accept, "application/json");
data = proxy.UploadString(url,"Post", obj); //Here got error
}
}
catch (Exception ex)
{
throw ex;
}
return data;
}
下面的WebAPI方法的代码,但在调试时要求不来这里都
[HttpPost]
public void Post(string lead)
{
//leadOptService.AddListOptions(lead);
}
请告诉我我在做什么错误以及如何解决。