0

我得到了“远程服务器返回错误:(400)错误请求。” 当我向 Quickbooks 添加新客户时.. 以下代码不起作用.. 为什么?

string Results = string.Empty;
        string requestUrl = null;
        requestUrl = "https://apps.quickbooks.com/j/AppGateway";


        HttpWebRequest WebRequestObject = null;
        StreamReader sr = null;
        HttpWebResponse WebResponseObject = null;
        StreamWriter stwr = null;


        try
        {
            WebRequestObject = (HttpWebRequest)WebRequest.Create(requestUrl);
            WebRequestObject.Method = "POST";
            WebRequestObject.ContentType = "application/x-qbxml";
            WebRequestObject.AllowAutoRedirect = false;
            string post = @"<?xml version=""1.0"" encoding=""utf-8""?>
<?qbxml version=""6.0""?>
<QBXML>
<SignonMsgsRq>
<SignonDesktopRq>
<ClientDateTime>%%CLIENT_DATE_TIME%%</ClientDateTime>
<ApplicationLogin>mydvqbapp.www.ipx2.com</ApplicationLogin>
<ConnectionTicket>TGT-142-6jCkNfIvWB$7Aw_ppW14jA</ConnectionTicket>
<Language>English</Language>
<AppID>APP_ID</AppID>
<AppVer>1</AppVer>
</SignonDesktopRq>
</SignonMsgsRq>
<QBXMLMsgsRq onError=""stopOnError"">
<CustomerAddRq>
<CustomerAdd> <!-- required -->
<Name >Sample Name</Name> <!-- required -->
<IsActive >True</IsActive> <!-- optional -->
<ClassRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</ClassRef>
<ParentRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</ParentRef>
<CompanyName >Sample CompanyName</CompanyName> <!-- optional -->
<Salutation >Mr</Salutation> <!-- optional -->
<FirstName >Sam Firstname</FirstName> <!-- optional -->
<MiddleName ></MiddleName> <!-- optional -->
<LastName >Sam LastName</LastName> <!-- optional -->
<JobTitle ></JobTitle> <!-- optional -->
<BillAddress> <!-- optional -->
<Addr1 >Sam Add1</Addr1> <!-- optional -->
<Addr2 >Sam Add2</Addr2> <!-- optional -->
<Addr3 ></Addr3> <!-- optional -->
<Addr4 ></Addr4> <!-- optional -->
<Addr5 ></Addr5> <!-- optional -->
<City ></City> <!-- optional -->
<State ></State> <!-- optional -->
<PostalCode ></PostalCode> <!-- optional -->
<Country ></Country> <!-- optional -->
<Note ></Note> <!-- optional -->
</BillAddress>
<ShipAddress> <!-- optional -->
<Addr1 ></Addr1> <!-- optional -->
<Addr2 ></Addr2> <!-- optional -->
<Addr3 ></Addr3> <!-- optional -->
<Addr4 ></Addr4> <!-- optional -->
<Addr5 ></Addr5> <!-- optional -->
<City ></City> <!-- optional -->
<State ></State> <!-- optional -->
<PostalCode ></PostalCode> <!-- optional -->
<Country ></Country> <!-- optional -->
<Note ></Note> <!-- optional -->
</ShipAddress>
<ShipToAddress> <!-- must occur 0 - 50 times -->
<Name >Test</Name> <!-- required -->
<Addr1 ></Addr1> <!-- optional -->
<Addr2 ></Addr2> <!-- optional -->
<Addr3 ></Addr3> <!-- optional -->
<Addr4 ></Addr4> <!-- optional -->
<Addr5 ></Addr5> <!-- optional -->
<City ></City> <!-- optional -->
<State ></State> <!-- optional -->
<PostalCode ></PostalCode> <!-- optional -->
<Country ></Country> <!-- optional -->
<Note ></Note> <!-- optional -->
<DefaultShipTo ></DefaultShipTo> <!-- optional -->
</ShipToAddress>
<Phone ></Phone> <!-- optional -->
<AltPhone ></AltPhone> <!-- optional -->
<Fax ></Fax> <!-- optional -->
<Email ></Email> <!-- optional -->
<Cc ></Cc> <!-- optional -->
<Contact ></Contact> <!-- optional -->
<AltContact ></AltContact> <!-- optional -->
<AdditionalContactRef> <!-- must occur 0 - 8 times -->
<ContactName ></ContactName> <!-- required -->
<ContactValue ></ContactValue> <!-- required -->
</AdditionalContactRef>
<Contacts> <!-- optional, may repeat -->
<Salutation ></Salutation> <!-- optional -->
<FirstName ></FirstName> <!-- required -->
<MiddleName ></MiddleName> <!-- optional -->
<LastName ></LastName> <!-- optional -->
<JobTitle ></JobTitle> <!-- optional -->
<AdditionalContactRef> <!-- must occur 0 - 5 times -->
<ContactName ></ContactName> <!-- required -->
<ContactValue ></ContactValue> <!-- required -->
</AdditionalContactRef>
</Contacts>
<CustomerTypeRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</CustomerTypeRef>
<TermsRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</TermsRef>
<SalesRepRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</SalesRepRef>
<OpenBalance ></OpenBalance> <!-- optional -->
<OpenBalanceDate ></OpenBalanceDate> <!-- optional -->
<SalesTaxCodeRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</SalesTaxCodeRef>
<ItemSalesTaxRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</ItemSalesTaxRef>
<ResaleNumber ></ResaleNumber> <!-- optional -->
<AccountNumber ></AccountNumber> <!-- optional -->
<CreditLimit ></CreditLimit> <!-- optional -->
<PreferredPaymentMethodRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</PreferredPaymentMethodRef>
<CreditCardInfo> <!-- optional -->
<CreditCardNumber ></CreditCardNumber> <!-- optional -->
<ExpirationMonth ></ExpirationMonth> <!-- optional -->
<ExpirationYear ></ExpirationYear> <!-- optional -->
<NameOnCard ></NameOnCard> <!-- optional -->
<CreditCardAddress ></CreditCardAddress> <!-- optional -->
<CreditCardPostalCode ></CreditCardPostalCode> <!-- optional -->
</CreditCardInfo>
<!-- JobStatus may have one of the following values: Awarded, Closed, InProgress, None [DEFAULT], NotAwarded, Pending -->
<JobStatus ></JobStatus> <!-- optional -->
<JobStartDate ></JobStartDate> <!-- optional -->
<JobProjectedEndDate ></JobProjectedEndDate> <!-- optional -->
<JobEndDate ></JobEndDate> <!-- optional -->
<JobDesc ></JobDesc> <!-- optional -->
<JobTypeRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</JobTypeRef>
<Notes ></Notes> <!-- optional -->
<AdditionalNotes> <!-- optional, may repeat -->
<Note ></Note> <!-- required -->
</AdditionalNotes>
<!-- PreferredDeliveryMethod may have one of the following values: None [Default], Email, Fax -->
<PreferredDeliveryMethod >ENUMTYPE</PreferredDeliveryMethod> <!-- optional -->
<PriceLevelRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</PriceLevelRef>
<ExternalGUID ></ExternalGUID> <!-- optional -->
<CurrencyRef> <!-- optional -->
<ListID ></ListID> <!-- optional -->
<FullName ></FullName> <!-- optional -->
</CurrencyRef>
</CustomerAdd>
<IncludeRetElement ></IncludeRetElement> <!-- optional, may repeat -->
</CustomerAddRq>
</QBXMLMsgsRq>
</QBXML>";
            post = post.Replace("%%CLIENT_DATE_TIME%%", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"));

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(post);
            post = xmlDoc.InnerXml;
            WebRequestObject.ContentLength = post.Length;
            stwr = new StreamWriter(WebRequestObject.GetRequestStream());
            stwr.Write(post);

            stwr.Close();
            WebResponseObject = (HttpWebResponse)WebRequestObject.GetResponse();
            sr = new StreamReader(WebResponseObject.GetResponseStream());
            Results = sr.ReadToEnd();
        }
        finally
        {
            try
            {
                lblMethod.Text = Results;
                sr.Close();

            }
            catch(Exception ex)
            {
                lblMethod.Text = "Error:<br/>" + ex.Message;
            }


            try
            {
                WebResponseObject.Close();
                WebRequestObject.Abort();
                lblMethod.Text = lblMethod.Text + "Sucessfully Connected";
            }
            catch (Exception ex)
            {
                lblMethod.Text = "Error:<br/>" + ex.Message;
            }
        }
    }

在上面的编码中,我得到了一个错误位置,“WebResponseObject = (HttpWebResponse)WebRequestObject.GetResponse();”

4

1 回答 1

1

您的 qbXML 远非 QuickBooks Online 有效。

如果您参考 QuickBooks OSR:http: //developer.intuit.com/qbsdk-current/common/newosr/index.html

以及 QuickBooks SDK 文档: https ://ipp.developer.intuit.com/0085_QuickBooks_Windows_SDK/010_qb

您会注意到 QuickBooks Online仅支持 qbXML 6.0 版。您尝试使用的许多功能都来自较新版本的 qbXML。例如:

  • 附加联系方式
  • 邮寄到地址

此外,QuickBooks Online 甚至根本不支持您使用的许多功能。例如:

  • 信用卡信息

确保将 OSR 设置为 6.0,并且仅选中“OE”复选框

这是一个工作请求的示例: http ://wiki.consolibyte.com/wiki/doku.php/quickbooks_qbxml_customeradd_with_parent

于 2012-11-08T16:27:08.277 回答