Hi Bernhard,

What I've done is just leverage the library's ability to generate the
Authorization header I required.  Then I just use standard
HttpWebRequests and put the header on myself.  Here's a non-optimized
example, you can factor out the repeatable parts into a utility.

...
            IOAuthSession apiSession = CreateSession(); //Construct a
session from your endpoints/Consumer keys etc.
            // Hint to the lib to focus on the header
            apiSession.ConsumerContext.UseHeaderForOAuthParameters =
true;

            apiSession.AccessToken = new TokenBase
            {
                Token = token,
                ConsumerKey = consumerKey,
                TokenSecret = secret
            };
            string testEndpoint = @"https://test.com/service";;

            IConsumerRequest testReq = apiSession.Request();
            custReq = testReq .Post();
            custReq = testReq .ForUrl(testEndpoint);
            custReq = testReq .SignWithToken();

            //Here's your Authorization Header
            string oAuthHeader =
testReq .Context.GenerateOAuthParametersForHeader();

            Uri address = new Uri(testEndpoint);

            HttpWebRequest request = WebRequest.Create(address) as
HttpWebRequest;
            request.Method = "POST";
            request.ContentType = "text/xml";
            // Set the generated Header
            request.Headers.Add("Authorization", oAuthHeader);
            using (Stream postStream = request.GetRequestStream())
            {
                //Serialize the request
                XmlSerializer serializer = new
XmlSerializer(typeof(MyType));
                serializer.Serialize(postStream, typeToSerialize);
                using (StringWriter sw = new StringWriter())
                {
                    serializer.Serialize(sw, TokenAuth);
                }
            }
            using (HttpWebResponse httpWebResponse =
(HttpWebResponse)request.GetResponse())
            {
                using (StreamReader reader = new
StreamReader(httpWebResponse.GetResponseStream()))
                    {
                       string responseString = reader.ReadToEnd();
                       Console.WriteLine(responseString);
                    }
                }
            }

Hope that helped,

Tim

On Jun 9, 3:00 am, Bernhard Schandl <[email protected]>
wrote:
> Hi,
>
> I am implementing an OAuth consumer using the DevDefined OAuth library
> for C#. I need to POST data to a remote server that is not
> "application/x-www-form-urlencoded" but XML; in consequence I cannot
> set the payload through request.WithFormParameters(). I didn't find a
> way how I can explicitly set the content and content-type, and I am
> also not sure whether the signing procedure supports that.
>
> Does anyone have experience with that? I am thankful for any support.
>
> Best regards
> Bernhard

-- 
You received this message because you are subscribed to the Google Groups 
"OAuth" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/oauth?hl=en.

Reply via email to