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();
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
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();
}
Karthi, It sounds like you are trying to do a GET request and add content to the body which would cause that error.
Please refer to the documentation on constructing the header for your request here: https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0050_Data_Services/0500_QuickBooks_Windows/0100_Calling_Data_Services/0010_Request_Header
regards, jarred
来源:https://stackoverflow.com/questions/13762746/add-xml-request-body-to-oauth-iconsumerrequest