Quickbooks Http Web请求代码提供400 Server错误

时间:2015-03-29 11:21:26

标签: asp.net .net oauth quickbooks quickbooks-online

我正在使用Quickbooks V3 SDK。它也提供了400错误,因为在2014年10月他们已经将他们的链接从https://quickbooks.api.intuit.com/更改为sandbox.quickbooks.api.intuit.com/,在更正后我可以获取结果和可以使用其提到的类执行crud操作。

 ServiceContext serviceContext = getServiceContext(profile);
            serviceContext.IppConfiguration.BaseUrl.Qbo = "https://sandbox-quickbooks.api.intuit.com/";
            QueryService<Item> ItemQueryService = new QueryService<Item>(serviceContext);
            return ItemQueryService.Select(c => c).ToList();

此代码完美无缺。

但是当我尝试使用HTTP Web请求执行与JSON请求相同的操作时,它会给我400错误。 我正在粘贴下面的HTTP Web请求代码。

HttpContext.Current.Session["serviceEndPoint"] = "https://qb.sbfinance.intuit.com/v3/company/" + profile.RealmId +"/item&query=select * from item"; //
        OAuthConsumerContext consumerContext = OAuthCR();

        OAuthSession oSession = OAuthSession(consumerContext);

        oSession.ConsumerContext.UseHeaderForOAuthParameters = true;

        oSession.AccessToken = new TokenBase
        {
            Token = profile.OAuthAccessToken,
            ConsumerKey = "qyprdB0F3beIfmSTdvpLG5J46xPGm2",
            TokenSecret = profile.OAuthAccessTokenSecret
        };


        IConsumerRequest conReq = oSession.Request();

        conReq = conReq.Post();
        conReq.AcceptsType = "application/json";
        conReq = conReq.ForUrl(HttpContext.Current.Session["serviceEndPoint"].ToString());


        string header = conReq.Context.GenerateSignatureBase();


        try
        {
            string res = conReq.ReadBody();

        }
        catch (WebException we)
        {
            HttpWebResponse rsp = (HttpWebResponse)we.Response;
            if (rsp != null)
            {
                try
                {
                    using (StreamReader reader = new StreamReader(rsp.GetResponseStream()))
                    {
                        string res2 = rsp.StatusCode + " | " + reader.ReadToEnd();


                    }
                }
                catch (Exception)
                {
                    string res = "Status code: " + rsp.StatusCode;
                }
            }
            else
            {
                string res = "Error Communicating with Mock Service" + we.Message;
            }
        }
    }

1 个答案:

答案 0 :(得分:0)