使用交我試圖通過使用Post方法JSON格式的原始數據,並將其存儲在其中具有特性,但被示出錯誤類。
我的價值控制器 - 代碼錯誤而在郵差
[HttpPost]
public void AddEmployee()
{
HttpWebRequest myHttpWebRequest`= (HttpWebRequest)WebRequest.Create("http://localhost:50278/api/values/AddEmployee");
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
////////Above line is giving error///////
Stream receiveStream = myHttpWebResponse.GetResponseStream();
DataContractJsonSerializer serializer =new DataContractJsonSerializer(typeof(Models.Employee));
Models.Employee user = (Models.Employee)serializer.ReadObject(receiveStream);
}
課堂,我想存儲在我的郵差後通過http://localhost:50278/api/values/AddEmployee
數據
Models.Employee
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public Nullable<System.DateTime> DOB { get; set; }
public Nullable<System.DateTime> DOJ { get; set; }
public Nullable<short> IsActivce { get; set; }
}
命令我的數據
[
{
"FirstName" : "ABDCD",
"MiddleName" :"sajsoa",
"LastName" : "KSJFHF",
"DOB":1994-01-12 00:00:00.0001994-01-12 00:00:00.000,
"DOJ":1994-01-12 00:00:00.0001994-01-12 00:00:00.000,
"Isactive" : 1
}
]
我收到了下面的錯誤r:
System.Net.WebException
發生在System.dll中,但未在用戶代碼中處理。
附加信息:
The remote server returned an error: (405) Method Not Allowed.
你能告訴爲什麼會顯示錯誤,日期格式是否正確?
請發表你得到 – phoenix
型「System.Net.WebException」的異常出現在System.dll中,但在用戶代碼中沒有處理 附加信息的錯誤信息:遠程服務器返回錯誤: (405)方法不允許。 –
爲什麼遞歸發送請求? – Fabio