Skip to content

Instantly share code, notes, and snippets.

@auniverseaway
Last active August 29, 2015 14:01
Show Gist options
  • Save auniverseaway/acafd834c20d7df3d329 to your computer and use it in GitHub Desktop.
Save auniverseaway/acafd834c20d7df3d329 to your computer and use it in GitHub Desktop.
RestSharp vs PortableRest (GET / POST)
// POST Working in RestSharp
var client = new RestClient(url);
var request = new RestRequest("/oauth/access_token?client_id=" + clientid + "&client_secret=" + clientsecret, Method.POST);
request.AddParameter("grant_type", "password");
request.AddParameter("username", username);
request.AddParameter("password", password);
client.ExecuteAsync(request, response =>
{
// Do stuff with the response
});
// GET Working in PortableRest
BaseUrl = url;
var request = new RestRequest("oauth/access_token?client_id=" + clientId + "&client_secret=" + clientSecret, HttpMethod.Get);
request.AddQueryString("username", username);
request.AddQueryString("password", password);
request.AddQueryString("grant_type", "password");
return await ExecuteAsync<Result>(request);
// POST *NOT* Working in PortableRest
// Error: "Index out of range"
BaseUrl = url;
var request = new RestRequest("oauth/access_token?client_id=" + clientId + "&client_secret=" + clientSecret, HttpMethod.Post);
request.AddHeader("Accept", "application/json, text/javascript, */*; q=0.01");
request.AddQueryString("username", username);
request.AddQueryString("password", password);
request.AddQueryString("grant_type", "password");
return await ExecuteAsync<Result>(request);
// POST NOT working in PortableRest
// Error: "Value cannot be NULL, Value: content"
BaseUrl = url;
var request = new RestRequest("oauth/access_token?client_id=" + clientId + "&client_secret=" + clientSecret, HttpMethod.Post);
request.AddParameter("username", username);
request.AddParameter("password", password);
request.AddParameter("grant_type", "password");
return await ExecuteAsync<Result>(request);
@robertmclaws
Copy link

I will add these to the PortableRest unit tests and see what happens. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment