Converting Postman Body form-data parameters to RestSharp C# POST request
Would anyone know how to convert the below Postman POST Body form-data parameters to RestSharp C# POST request, nothing I have tries worked for me so far. The end point is using OAuth 1.0, and I can post succesfully only with Body form-data, no other Body options do the trick.
The postman RestSharp translated to:
var client = new RestClient("https://openapi.etsy.com/v2/shipping/templates");
var request2 = new RestRequest(Method.POST);
request2.AddHeader("cache-control", "no-cache");
request2.AddHeader("authorization", "OAuth oauth_consumer_key=" + consumerKey + ",oauth_token=" + oAuthToken + ",oauth_signature_method="HMAC-SHA1",oauth_timestamp="+ timeStamp + ",oauth_nonce=" + nonce +",oauth_version="1.0",oauth_signature=" + sig + "");
request2.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request2.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="title"rnrntest titlern------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="origin_country_id"rnrn209rn------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="primary_cost"rnrn1rn------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="secondary_cost"rnrn1rn------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response2 = client.Execute(request2);
But this does not work with RestSharp, it throws StatusCode Forbidden, and Content 'oauth_problem=signature_invalid...'
How to make it work? The parameters can be only passed in with Body form-data
Update: Code used for generating nonce, timestamp, signature, etc:
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.POST.ToString(), timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters);
c# api postman restsharp
add a comment |
Would anyone know how to convert the below Postman POST Body form-data parameters to RestSharp C# POST request, nothing I have tries worked for me so far. The end point is using OAuth 1.0, and I can post succesfully only with Body form-data, no other Body options do the trick.
The postman RestSharp translated to:
var client = new RestClient("https://openapi.etsy.com/v2/shipping/templates");
var request2 = new RestRequest(Method.POST);
request2.AddHeader("cache-control", "no-cache");
request2.AddHeader("authorization", "OAuth oauth_consumer_key=" + consumerKey + ",oauth_token=" + oAuthToken + ",oauth_signature_method="HMAC-SHA1",oauth_timestamp="+ timeStamp + ",oauth_nonce=" + nonce +",oauth_version="1.0",oauth_signature=" + sig + "");
request2.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request2.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="title"rnrntest titlern------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="origin_country_id"rnrn209rn------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="primary_cost"rnrn1rn------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="secondary_cost"rnrn1rn------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response2 = client.Execute(request2);
But this does not work with RestSharp, it throws StatusCode Forbidden, and Content 'oauth_problem=signature_invalid...'
How to make it work? The parameters can be only passed in with Body form-data
Update: Code used for generating nonce, timestamp, signature, etc:
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.POST.ToString(), timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters);
c# api postman restsharp
Show the code where you set the consumerkey,oauthtoken,nonce etc.
– Caius Jard
Dec 31 '18 at 6:17
I don't know about C#, but just curious: did you use Postman's Code Generator to generate this code?
– Sivcan Singh
Dec 31 '18 at 12:24
yes, This is the exact code generated by Postman for c# RestSharp
– lucas
Dec 31 '18 at 17:25
The code for setting up the nonce, timestamp, etc is generated correctly, it is the same method I have used when generating these for my HTTP GET calls, and HTTP GET works just fine, HTTP POST is the only one failing. It is got to be related to how I post the data
– lucas
Dec 31 '18 at 17:27
add a comment |
Would anyone know how to convert the below Postman POST Body form-data parameters to RestSharp C# POST request, nothing I have tries worked for me so far. The end point is using OAuth 1.0, and I can post succesfully only with Body form-data, no other Body options do the trick.
The postman RestSharp translated to:
var client = new RestClient("https://openapi.etsy.com/v2/shipping/templates");
var request2 = new RestRequest(Method.POST);
request2.AddHeader("cache-control", "no-cache");
request2.AddHeader("authorization", "OAuth oauth_consumer_key=" + consumerKey + ",oauth_token=" + oAuthToken + ",oauth_signature_method="HMAC-SHA1",oauth_timestamp="+ timeStamp + ",oauth_nonce=" + nonce +",oauth_version="1.0",oauth_signature=" + sig + "");
request2.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request2.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="title"rnrntest titlern------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="origin_country_id"rnrn209rn------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="primary_cost"rnrn1rn------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="secondary_cost"rnrn1rn------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response2 = client.Execute(request2);
But this does not work with RestSharp, it throws StatusCode Forbidden, and Content 'oauth_problem=signature_invalid...'
How to make it work? The parameters can be only passed in with Body form-data
Update: Code used for generating nonce, timestamp, signature, etc:
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.POST.ToString(), timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters);
c# api postman restsharp
Would anyone know how to convert the below Postman POST Body form-data parameters to RestSharp C# POST request, nothing I have tries worked for me so far. The end point is using OAuth 1.0, and I can post succesfully only with Body form-data, no other Body options do the trick.
The postman RestSharp translated to:
var client = new RestClient("https://openapi.etsy.com/v2/shipping/templates");
var request2 = new RestRequest(Method.POST);
request2.AddHeader("cache-control", "no-cache");
request2.AddHeader("authorization", "OAuth oauth_consumer_key=" + consumerKey + ",oauth_token=" + oAuthToken + ",oauth_signature_method="HMAC-SHA1",oauth_timestamp="+ timeStamp + ",oauth_nonce=" + nonce +",oauth_version="1.0",oauth_signature=" + sig + "");
request2.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request2.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="title"rnrntest titlern------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="origin_country_id"rnrn209rn------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="primary_cost"rnrn1rn------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="secondary_cost"rnrn1rn------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response2 = client.Execute(request2);
But this does not work with RestSharp, it throws StatusCode Forbidden, and Content 'oauth_problem=signature_invalid...'
How to make it work? The parameters can be only passed in with Body form-data
Update: Code used for generating nonce, timestamp, signature, etc:
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.POST.ToString(), timeStamp, nonce, out normalizedUrl, out normalizedRequestParameters);
c# api postman restsharp
c# api postman restsharp
edited Dec 31 '18 at 17:28
lucas
asked Dec 31 '18 at 3:44
lucaslucas
1,47521330
1,47521330
Show the code where you set the consumerkey,oauthtoken,nonce etc.
– Caius Jard
Dec 31 '18 at 6:17
I don't know about C#, but just curious: did you use Postman's Code Generator to generate this code?
– Sivcan Singh
Dec 31 '18 at 12:24
yes, This is the exact code generated by Postman for c# RestSharp
– lucas
Dec 31 '18 at 17:25
The code for setting up the nonce, timestamp, etc is generated correctly, it is the same method I have used when generating these for my HTTP GET calls, and HTTP GET works just fine, HTTP POST is the only one failing. It is got to be related to how I post the data
– lucas
Dec 31 '18 at 17:27
add a comment |
Show the code where you set the consumerkey,oauthtoken,nonce etc.
– Caius Jard
Dec 31 '18 at 6:17
I don't know about C#, but just curious: did you use Postman's Code Generator to generate this code?
– Sivcan Singh
Dec 31 '18 at 12:24
yes, This is the exact code generated by Postman for c# RestSharp
– lucas
Dec 31 '18 at 17:25
The code for setting up the nonce, timestamp, etc is generated correctly, it is the same method I have used when generating these for my HTTP GET calls, and HTTP GET works just fine, HTTP POST is the only one failing. It is got to be related to how I post the data
– lucas
Dec 31 '18 at 17:27
Show the code where you set the consumerkey,oauthtoken,nonce etc.
– Caius Jard
Dec 31 '18 at 6:17
Show the code where you set the consumerkey,oauthtoken,nonce etc.
– Caius Jard
Dec 31 '18 at 6:17
I don't know about C#, but just curious: did you use Postman's Code Generator to generate this code?
– Sivcan Singh
Dec 31 '18 at 12:24
I don't know about C#, but just curious: did you use Postman's Code Generator to generate this code?
– Sivcan Singh
Dec 31 '18 at 12:24
yes, This is the exact code generated by Postman for c# RestSharp
– lucas
Dec 31 '18 at 17:25
yes, This is the exact code generated by Postman for c# RestSharp
– lucas
Dec 31 '18 at 17:25
The code for setting up the nonce, timestamp, etc is generated correctly, it is the same method I have used when generating these for my HTTP GET calls, and HTTP GET works just fine, HTTP POST is the only one failing. It is got to be related to how I post the data
– lucas
Dec 31 '18 at 17:27
The code for setting up the nonce, timestamp, etc is generated correctly, it is the same method I have used when generating these for my HTTP GET calls, and HTTP GET works just fine, HTTP POST is the only one failing. It is got to be related to how I post the data
– lucas
Dec 31 '18 at 17:27
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53983394%2fconverting-postman-body-form-data-parameters-to-restsharp-c-sharp-post-request%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53983394%2fconverting-postman-body-form-data-parameters-to-restsharp-c-sharp-post-request%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Show the code where you set the consumerkey,oauthtoken,nonce etc.
– Caius Jard
Dec 31 '18 at 6:17
I don't know about C#, but just curious: did you use Postman's Code Generator to generate this code?
– Sivcan Singh
Dec 31 '18 at 12:24
yes, This is the exact code generated by Postman for c# RestSharp
– lucas
Dec 31 '18 at 17:25
The code for setting up the nonce, timestamp, etc is generated correctly, it is the same method I have used when generating these for my HTTP GET calls, and HTTP GET works just fine, HTTP POST is the only one failing. It is got to be related to how I post the data
– lucas
Dec 31 '18 at 17:27