I'm currently working with Spreedly REST API which works with basic http authentication.
At first, I set my credentials this way:
webRequest.Credentials = new System.Net.NetworkCredential(user, password);
It worked well for many of the API resources including POSTing new gateways, GETing gateways, PUTing data on a gateway and even redacting a gateway.
I hit a wall when I tried to POST a new payment_method at their /v1/payment_methods.<format>
resource.
The error I'm getting:
HTTP 422
{
"errors": [
{
"key": "errors.environment_key_parameter_required",
"message": "You must specify an environment_key parameter."
}
]
}
After verifying a lot of things, I tried it using curl based on their examples and it worked.
The issue seems to be in the way I set my credentials in the HttpWebRequest even though it's the same code I use for the other working resources.
I tried using the CredentialCache because I could specify "Basic" and it failed the same way:
CredentialCache cache = new CredentialCache();
cache.Add(webRequest.RequestUri, "Basic", new System.Net.NetworkCredential(user, password));
webRequest.Credentials = cache;