问题
I am trying to post the below xml to https://apps.quickbooks.com/j/AppGateway and all I keep getting is the error: The remote server returned an error: (400) Bad Request. Does anyone have any ideas what I am doing wrong? See below for the C# code that I am using to post the xml.
Thanks, -Jeff
UPDATE: To add more to my question, I am thinking that the (400) Bad Request error is indicating that I have something grossly wrong with the xml or with the way I am posting the xml. So that is why I am asking this question... what am I missing here?
<?xml version="1.0" encoding="utf-8" ?>
<?qbxml version="7.0"?>
<QBXML>
<SignonMsgsRq>
<SignonDesktopRq>
<ClientDateTime>7/20/2009 12:36PM</ClientDateTime>
<ApplicationLogin>APP_LOGIN</ApplicationLogin>
<ConnectionTicket>CONNECTION_TICKET</ConnectionTicket>
<Language>English</Language>
<AppID>APP_ID</AppID>
<AppVer>1</AppVer>
</SignonDesktopRq>
</SignonMsgsRq>
<QBXMLMsgsRq>
<CustomerQueryRq requestID="2" />
</QBXMLMsgsRq>
</QBXML>
WebRequestObject = (HttpWebRequest)WebRequest.Create(requestUrl);
WebRequestObject.Method = "POST";
WebRequestObject.ContentType = "application/x-qbxml";
WebRequestObject.AllowAutoRedirect = false;
string post = XmlText.Text;
WebRequestObject.ContentLength = post.Length;
swr = new StreamWriter(WebRequestObject.GetRequestStream());
swr.Write(post);
swr.Close();
WebResponseObject = (HttpWebResponse)WebRequestObject.GetResponse();
回答1:
Change your qbXML version to 6.0, QuickBooks Online Edition doesn't support 7.0 yet.
回答2:
where is the xml posted in request?? Or you are missing to paste some code here. I don't see the request has XML in the above code. The request is bad because the request contain no XML. At least from what I see above
回答3:
As Keith Palmer mentioned in his answer the version number needs to be 6.0 but also need to include the onError attribute of the QBXMLMsgsRq tag. (I also corrected the time format too as recommend by Keith Palmer.)
Complete/working xml is here:
<?xml version="1.0" encoding="utf-8" ?>
<?qbxml version="6.0"?>
<QBXML>
<SignonMsgsRq>
<SignonDesktopRq>
<ClientDateTime>2009-07-21T10:10:00</ClientDateTime>
<ApplicationLogin>APPLICATION_LOGIN</ApplicationLogin>
<ConnectionTicket>CONNECTION_TICKET</ConnectionTicket>
<Language>English</Language>
<AppID>APP_ID</AppID>
<AppVer>1</AppVer>
</SignonDesktopRq>
</SignonMsgsRq>
<QBXMLMsgsRq onError="continueOnError">
<CustomerQueryRq requestID="2" />
</QBXMLMsgsRq>
</QBXML>
回答4:
You can get the XML for a customer query at this site:
QuickBooks Online OSR
Select CustomerQuery as the message. Use Chrome because it doesn't work in all browsers. Click XmlOps and you'll see the XML.
On another note, I have a commercial solution available here:
QuickBooks Online C# Development Integration
来源:https://stackoverflow.com/questions/1154880/valid-xml-for-posting-to-quickbooks-online-edition-receiving-400-bad-request