XML请求主体添加到OAuth IConsumerRequest [英] add XML request body to Oauth IConsumerRequest

查看:228
本文介绍了XML请求主体添加到OAuth IConsumerRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我就从忒Anywhere.The过程涉及读取数据的一个项目工作的正常工作时,通过OAuth签署了URL是作为发送一些request.Can一个可以帮助我如何将XML请求添加到IConsumerRequest的身体。

hi all am working on a project that involves Fetching data from Intuit Anywhere.The process works fine when a url signed with Oauth is send as request.Can some one help me how to add xml request to the body of IConsumerRequest.

  OAuthConsumerContext consumerContext = new OAuthConsumerContext
                {
                    ConsumerKey = "consumerkey",
                    SignatureMethod = SignatureMethod.HmacSha1,
                    ConsumerSecret = "consumersecret"
                };

  OAuthSession oSession = new OAuthSession(consumerContext, "https://oauth.intuit.com/oauth/v1/get_request_token",
                                        "https://workplace.intuit.com/Connect/Begin",
                                        "https://oauth.intuit.com/oauth/v1/get_access_token");

                oSession.ConsumerContext.UseHeaderForOAuthParameters = true;
                oSession.AccessToken = new TokenBase
                {
                    Token = Session["accessToken"].ToString(),
                    ConsumerKey = "consumerkey",
                    TokenSecret = Session["accessTokenSecret"].ToString()
                };

                IConsumerRequest conReq = oSession.Request();
                 string body = @"<?xml version=""1.0"" encoding=""utf-8""?>
    <AccountQuery xmlns=""http://www.intuit.com/sb/cdm/v2"">
      <ListIdSet>
        <Id idDomain=""QB"">143</Id>
        <Id idDomain=""QB"">130</Id>
      </ListIdSet>
    </AccountQuery>";
                    conReq = conReq.Get();
                conReq = conReq.ForUrl("https://services.intuit.com/sb/account/v2/536779769");
  conReq.RequestBody=body;
                   try
                {
                    conReq = conReq.SignWithToken();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                string header = conReq.Context.GenerateOAuthParametersForHeader();
                string serviceResponse = conReq.ReadBody();



我得到一个错误无法发送内容体与这个动词type.Can有人点我是什么误差或是否有可能做同样的Web请求?请帮助

i get an error Cannot send a content-body with this verb-type.Can someone point me what the error is or Is it possible to do the same with a web request? Please help

推荐答案

这是worked.Below示例代码,我从直觉forums-
https://idnforums.intuit.com/messageview.aspx?catid=86&主题ID = 18870&安培; enterthread = Y

this worked.Below is the example code i got from intuit forums- https://idnforums.intuit.com/messageview.aspx?catid=86&threadid=18870&enterthread=y

 //using DevDefined.OAuth.Consumer;
//using DevDefined.OAuth.Framework;

protected void GetBalanceSheet()
{
    OAuthConsumerContext consumerContext = new OAuthConsumerContext
    {
        ConsumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(),
        SignatureMethod = SignatureMethod.HmacSha1,
        ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString()
    };

    OAuthSession oSession = new OAuthSession(consumerContext, "https://oauth.intuit.com/oauth/v1/get_request_token",
                            "https://workplace.intuit.com/Connect/Begin",
                            "https://oauth.intuit.com/oauth/v1/get_access_token");

    oSession.ConsumerContext.UseHeaderForOAuthParameters = true;

    oSession.AccessToken = new TokenBase
    {
        Token = Session["accessToken"].ToString(),
        ConsumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(),
        TokenSecret = Session["accessTokenSecret"].ToString()
    };

    var body = "<AdvancedReportQuery xmlns=\"http://www.intuit.com/sb/cdm/v2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.intuit.com/sb/cdm/v2 ..//RestDataFilter.xsd\"><BalanceSheetStd><OfferingId>ipp</OfferingId><EndTransactionDate>2012-06-01</EndTransactionDate></BalanceSheetStd></AdvancedReportQuery>";

    IConsumerRequest conReq = oSession.Request();
    conReq = conReq.Post().WithRawContentType("text/xml").WithRawContent(System.Text.Encoding.ASCII.GetBytes(body)); ;
    conReq = conReq.ForUrl("https://services.intuit.com/sb/advancedreport/v2/508053445");
    try
    {
        conReq = conReq.SignWithToken();
    }
    catch (Exception ex)
    {
        throw ex;
    }

    string serviceResponse = conReq.ReadBody();

}

这篇关于XML请求主体添加到OAuth IConsumerRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆