How to get published data in MVC action?

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.

+3
4

post xml InputStream Request.

      public ActionResult BuildPreview(string hwid, string label, string localization)
         {
             StreamReader streamReader = new StreamReader(Request.InputStream);
             XmlDocument xmlDocument = new XmlDocument();
             xmlDocument.LoadXml(streamReader.ReadToEnd());
               ... 

 }
+3

Request.Form RouteData , , - .

+5

As a measure of stop space, you can always change the action of your controller to accept a parameter FormCollection, and then access and access form parameters by name directly.

+2
source

To get the original bytes with WebClient.UploadData("http://somewhere/BuildPreview", bytes)

public ActionResult BuildPreview()
{
    byte[] b;
    using (MemoryStream ms = new MemoryStream())
    {
        Request.InputStream.CopyTo(ms);
        b = ms.ToArray();
    }

    ...
}
0
source

All Articles