I have a RESTful Apex service that I can browse to and call using my web browser.
A problem occurs when I try to call it from C#:
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (400) Bad Request.
This is my code:
using (var client = new WebClient())
{
var url = $"https://x.force.com/activations/services/apexrest/sample/get?id=123";
var json = client.DownloadString(url);
}
How can I call this RESTful service from C#? It works just fine from an unauthorized browser. The service itself returns a set of JSON which I would like to parse.
Edit: Just to clarify, my RESTful service is exposed as a force.com site and I can hit its controller methods from a fresh browser with a completely clean browsing history and get a response back (never having to type in my username or password or anything).