I have a WebAPI project which was generated by the Visual Studio 2015 wizard. In it, I have added a controller that contains a GET handler:
public Task<string> Get (int id)
{
using (var wb = new WebClient())
{
var data = new NameValueCollection();
data["username"] = "myUser";
data["password"] = "myPassword";
var response = wb.UploadValues(<project URL, ends with a value for the id
parm>, "POST", data);
}
return null;
}
And I have the following method:
[HttpPost]
public NameValueCollection Post(int id, [FromBody] NameValueCollection data)
{
return data;
}
I find that although I have deliberately hard-coded the data in the GET handler, when the POST method gets invoked, the data parameter always has a .Count of 0. Upon return to the GET, it has a .Count of 2, exactly as it started out. I have tried a dozen different methods of invoking the POST, taken from various articles online. In every case, the behavior is the same: the POST method receives no data. The id parameter always has the correct value passed in to the GET method.
Does anyone have a clue about what might be going wrong?
What I have tried:
I have tried a dozen different methods from articles found on the web.