I am trying to send some data to an ASP.NET MVC Controller action. I am currently trying to use WebClient.UploadData () to post some parameters for my action.
The following actions will be deleted, but all parameters are zero. How to get published data from an HTTP request?
string postFormat = "hwid={0}&label={1}&interchange={2}localization={3}";
var hwid = interchangeDocument.DocumentKey.Hwid;
var interchange = HttpUtility.UrlEncode(sw.ToString());
var label = ConfigurationManager.AppSettings["PreviewLabel"];
var localization = interchangeDocument.DocumentKey.Localization.ToString();
string postData = string.Format(postFormat, hwid, interchange, label, localization);
using(WebClient client = new WebClient())
{
client.Encoding = Encoding.UTF8;
client.Credentials = CredentialCache.DefaultNetworkCredentials;
byte[] postArray = Encoding.ASCII.GetBytes(postData);
client.Headers.Add("Content-Type", "pplication/x-www-form-urlencoded");
byte[] reponseArray = client.UploadData("http://localhost:6355/SymptomTopics/BuildPreview",postArray);
var result = Encoding.ASCII.GetString(reponseArray);
return result;
}
Here is the action I call
public ActionResult BuildPreview (hwid line, line label, exchange line, localization line) {...}
Upon reaching this action, all parameters are equal to zero.
I tried using WebClient.UploadValue () and passed the data as NameValueCollection. This method always returns status 500 and because I am making this http request from an MVC application, I cannot find a way to bebug it.
.
-Nick
, :
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
UploadData 500.