I am running into a difficulty with HTTP POST and Oauth 1, RestClient C#. I am able to make successful calls with HTTP GET and Oauth, but for some reason HTTP Post fails. I was able to make successful HTTP POST calls with same credentials using Postman, but not with RestSharp. Perhaps someone could help me figuring out the issue.
Here are the screenshots with working HTTP POST Oauth1 Postman call:
The Postman setup above works just fine, and here is what I have so far in C# and RestClient:
public bool CreateShippingTemplate(string storeProviderStoreId, string consumerKey, string consumerSecret, string oAuthToken, string oAuthTokenSecret)
{
string url = "/shipping/templates";
var request = GenerateSecureRequest(url, RequestType.POST, consumerKey, consumerSecret, oAuthToken, oAuthTokenSecret);
var dataObj = new //ShippingTemplate
{
title = "Test Title 2",
origin_country_id = "209",
primary_cost = "1",
secondary_cost = "1"
};
string dataObjJson = JsonConvert.SerializeObject(dataObj);
request.AddParameter("application/json", dataObjJson, ParameterType.RequestBody);
request.RequestFormat = DataFormat.Json;
request.Method = Method.POST;
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
var response = _restClient.ExecuteAsPost(request,"POST");
return true;
}
private RestRequest GenerateSecureRequest(string url, RequestType requestType, string consumerKey, string consumerSecret, string oAuthToken, string oAuthTokenSecret)
{
OAuthBase oAuth = new OAuthBase();
string nonce = oAuth.GenerateNonce();
string timeStamp = oAuth.GenerateTimeStamp();
string normalizedUrl;
string normalizedRequestParameters;
string relativeUri = url;
string sig = oAuth.GenerateSignature(new Uri(BASE_URL.ToString() + relativeUri), consumerKey, consumerSecret, oAuthToken, oAuthTokenSecret, requestType.ToString(), timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters);
var request = new RestRequest(relativeUri);
request.Resource = string.Format(relativeUri);
request.Method = Method.GET;
request.AddParameter("oauth_consumer_key", consumerKey);
request.AddParameter("oauth_token", oAuthToken);
request.AddParameter("oauth_nonce", nonce);
request.AddParameter("oauth_timestamp", timeStamp);
request.AddParameter("oauth_signature_method", "HMAC-SHA1");
request.AddParameter("oauth_version", "1.0");
request.AddParameter("oauth_signature", sig);
return request;
}
I tried many things with RestClient and C#, nothing worked. What am I missing, in order to match the working Postman request. HTTP GET is working for me in RestSharp, only HTTP Post is not working.
Thank you


