1

大家好,我正在从事一个涉及从 Intuit Anywhere 获取数据的项目。当使用 Oauth 签名的 url 作为请求发送时,该过程工作正常。有人可以帮助我如何将 xml 请求添加到 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();

我收到一个错误无法发送具有此动词类型的内容正文。有人可以指出错误是什么,或者是否可以对 Web 请求执行相同的操作?请帮忙

4

2 回答 2

2

这很有效。下面是我从 intuit 论坛获得的示例代码 - 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();

}
于 2012-12-08T08:43:04.803 回答
0

Karthi,听起来您正在尝试执行 GET 请求并将内容添加到正文中,这会导致该错误。

请参阅有关为您的请求构建标头的文档: https ://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0500_QuickBooks_Windows/0100_Calling_Data_Services/0010_Request_Header

问候,震惊

于 2012-12-07T16:22:39.947 回答