Im trying to do a simple test with the REST API based on their cURL example: https://developer.paypal.com/docs/integration/direct/make-your-first-call/
curl -v https://api.sandbox.paypal.com/v1/oauth2/token \ -H "Accept: application/json" \ -H "Accept-Language: en_US" \ -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" \ -d "grant_type=client_credentials" My C#:
var h = new HttpClientHandler(); h.Credentials = new NetworkCredential("client_id", "secret"); var client = new HttpClient(); client.BaseAddress = new Uri("https://api.sandbox.paypal.com/v1/oauth2/token"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("Accept-Language", "en_US"); var requestContent = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("grant_type", "client_credentials"), }); HttpRequestMessage req = new HttpRequestMessage(System.Net.Http.HttpMethod.Post, "https://api.sandbox.paypal.com/v1/oauth2/token"); req.Content = new StringContent("grant_type=client_credentials"); var r = client.SendAsync(req).Result; Error returned:
StatusCode: 415, ReasonPhrase: 'Unsupported Media Type', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { PROXY_SERVER_INFO: host=slcsbjava2.slc.paypal.com;threadId=13873 Paypal-Debug-Id: 6bc39da1e021d SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=351&TopLevelTxnStartTime=14649fa185e&Host=slcsbidensectoken501.slc.paypal.com&pid=25122 CORRELATION-ID: 6bc39da1e021d Transfer-Encoding: chunked Date: Thu, 29 May 2014 21:54:25 GMT Server: Apache-Coyote/1.1 } What do I need to change to fix my code?