RestSharp C # HTTP POST OAUT 1 - PullRequest
       10

RestSharp C # HTTP POST OAUT 1

0 голосов
/ 30 декабря 2018

У меня проблемы с HTTP POST и Oauth 1, RestClient C #.Я могу совершать успешные звонки с помощью HTTP GET и Oauth, но по какой-то причине HTTP Post не удается.Мне удалось сделать успешные вызовы HTTP POST с теми же учетными данными, используя Postman, но не с RestSharp.Возможно, кто-то может помочь мне разобраться в проблеме.

Вот скриншоты с работающим HTTP POST Oauth1 Вызов почтальона:

enter image description here

enter image description here

enter image description here

Приведенная выше настройка Postman работает просто отлично, и вот что я пока имею в C # и 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перепробовал много вещей с RestClient и C #, ничего не получалось.Чего мне не хватает, чтобы соответствовать рабочему запросу Почтальона.HTTP GET работает для меня в RestSharp, только HTTP Post не работает.

Спасибо

...