0

I know that if you want to POST a variable to Web API with WebClient you do not include the parameter key

using (WebClient client = new WebClient())
{
    string URI = "http://blablabla/api/testaction";
    string myParameters = "=TEST";

    using (WebClient wc = new WebClient())
    {
        wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

        string HtmlResult = wc.UploadString(URI, myParameters);
    }
}

My question is why can't you include the parameter key?

string myParameters = "myParam=TEST"; // doesn't work

What do you do if you want to pass more than one parameter?

Craig W.
  • 17,838
  • 6
  • 49
  • 82
MightyAtom
  • 331
  • 4
  • 24
  • string HtmlResult = wc.UploadString(URI, myParameters); // might it be download instead of uploaed ? If it's a post action check if you can hit the Api method in debug – Kubi Feb 11 '15 at 14:42

1 Answers1

0

you should write parameters like

http://blablabla/api/testaction?parmeterName=parameterValue?pName=pValue

So basically I would write it like this

string URI = "http://blablabla/api/testaction";
string myParameters = "?param=TEST";
  • this does not work with Web Api. The route action matches but the parameter is null – MightyAtom Feb 10 '15 at 15:46
  • Are you talking about the parameter inside the API controller ? If so, then ignor what i have answered until now, the parameter inside the controller must be a string, and the address it self should just be the URI from my answer – Henrik Bøgelund Lavstsen Feb 10 '15 at 15:53