У меня есть MVC-действие .....
[HttpPost]
public ActionResult DoStuff(string myString, DateTime myDateTime)
... и я вызываю действие из компактного фреймворк-приложения вот так .....
WebRequest request = WebRequest.Create(url);
// Set the Method property of the request to POST.
request.Method = "POST";
request.Proxy = null;
// Create POST data and convert it to a byte array.
string postData = "myString=Bonjour&myDateTime=" + DateTime.Now.ToString();
byte[] byteArray = Encoding.UTF8.GetBytes(jsonPostData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
// Get the response.
using (WebResponse response = request.GetResponse())
{
// Display the status.
// Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
using (Stream responseStream = response.GetResponseStream())
{
// Read the response...
using (StreamReader reader = new StreamReader(responseStream))
{
Console.WriteLine(reader.ReadToEnd());
}
}
}
Проблема в том, что параметр "myDateTime" всегда равен нулю?В каком формате должна быть строка postData, чтобы это работало (я пробовал довольно много!)?
Большое спасибо,
ETFairfax