I am trying send HttpPost request from Android to C# (.net 3.5) aspx server. I am using Apache multipart entity builder builds entity at Android side:
entityBuilder.addTextBody("username", username);
entityBuilder.addTextBody("password", password);
entityBuilder.addBinaryBody("file", file);
And try to get data at C# server side:
protected void Page_Load(object sender, EventArgs e)
{
string[] keys = Request.Form.AllKeys; // only username and password keys received.
for (int i = 0; i < keys.Length; i++)
{
string [] tmp = Request.Form.GetValues (keys[i]);
}
}
I can get TextBody part keys and values in the Request (username and password). But no BinaryBody key or data received. I do not know why?
Solution:
HttpFileCollection MyFiles = Request.Files;
// ...
for (int l = 0; l < MyFiles.Count; l++)
{
if (MyFiles.GetKey(l) == "file")
{
HttpPostedFile file = MyFiles.Get("file");
// ...
}
}