I'm trying to post a request from one server to a second, which is using the WebAPI techology. This is my method that receives the call
[HttpGet]
[HttpPost]
public HttpResponseMessage MyMethod([FromBody] string token, [FromBody] string email, [FromBody] string password)
{
string a = "hello world!";
return new HttpResponseMessage() { Content = new StringContent(a) };
}
I am using this code post to to it:
using (var c = new WebClient())
{
//string obj = ":" + JsonConvert.SerializeObject(new { token= "token", email="email", password="password" });
NameValueCollection myNameValueCollection = new NameValueCollection();
// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("token", "token");
myNameValueCollection.Add("email", "email");
myNameValueCollection.Add("password", "password");
byte[] responseArray = c.UploadValues("MyServer/MyMethod", "POST", myNameValueCollection);
return Encoding.ASCII.GetString(responseArray);
}
I've tried several alternatives.
This one I wrote above gives me an Internal Server Error and My breakpoint inside MyMethod isn't hit, so the problem is not on my method's code.
Commenting the three lines that add parameters to my nameValueCollection, I get a 404.
Removing the parameters form the signature of MyMethod, it works.
I would like to post this information to my server that hosts the API.
Do you know what I am doing wrong?