大家正在研究一个涉及从Intuit Anywhere获取数据的项目。当使用Oauth签名的URL作为请求发送时,该过程正常工作。可以帮助我如何将xml请求添加到IConsumerRequest的主体。 / p>
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请求执行相同操作?请帮忙
答案 0 :(得分:2)
这个工作.Below是我从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();
}
答案 1 :(得分:0)
卡, 听起来您正在尝试执行GET请求并向正文添加内容,这会导致该错误。
请参阅有关为您的请求构建标题的文档: https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0500_QuickBooks_Windows/0100_Calling_Data_Services/0010_Request_Header
的问候, 震动