Results 1 to 12 of 12

Thread: Send XML 1st line to Amazon

  1. #1
    Join Date
    Jun 2014
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Send XML 1st line to Amazon

    Hi,

    I'm having trouble sending XML 1st line to Amazon. I have googled around but haven't been able to implement what I've found. Any help would be much appreciated.

    I am using Qt 5.3

    Thanks,

    Richard
    Last edited by Poonarge; 7th July 2014 at 17:25.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Send XML 1st line to Amazon

    This does not contain enough information.

    At which stage to you get into problems? Creating the XML? Sending it? How does you current code look like? What does it do that you do not expect? What does it not do that you would expect it to do?

    Cheers,
    _

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Send XML 1st line to Amazon

    What does "XML 1st line" even mean?

  4. #4
    Join Date
    Jun 2014
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Send XML 1st line to Amazon

    Quote Originally Posted by anda_skoa View Post
    At which stage to you get into problems? Creating the XML? Sending it? How does you current code look like? What does it do that you do not expect? What does it not do that you would expect it to do?
    Sorry for being brief. I'm having trouble sending the XML, each time I get an invalid reply. See below:

    Request:
    Qt Code:
    1. QByteArray XMLTest;
    2.  
    3. QXmlStreamWriter swTest(&XMLTest);
    4. swTest.setAutoFormatting(true);
    5. swTest.writeStartDocument();
    6. swTest.writeEndDocument();
    7.  
    8. QUrl Params(BuildRequest(1, account, marketplaces));
    9.  
    10. QNetworkRequest request(Params);
    11.  
    12. QString BodyMD5 = QString(QCryptographicHash::hash((XMLTest),QCryptographicHash::Md5).toHex());
    13.  
    14. request.setRawHeader("Content-Type", "text/xml; charset=iso-8859-1");
    15. request.setRawHeader("Content-MD5", BodyMD5.toLatin1().toBase64());
    16. request.setRawHeader("User-Agent", "TestBuild");
    17. request.setRawHeader("Host", "mws.amazonservices.co.uk");
    18. request.setRawHeader("Transfer-Encoding", "chunked");
    19. request.setRawHeader("MWSClientVersion", "2009-03-09");
    20.  
    21. QNetworkAccessManager test;
    22.  
    23. QEventLoop loop2;
    24. connect(&test, SIGNAL(finished(QNetworkReply*)), &loop2, SLOT(quit()));
    25. QNetworkReply *reply = test.post(request, request.url().query().toUtf8());
    26. loop2.exec();
    27.  
    28. QString str = reply->readAll();
    To copy to clipboard, switch view to plain text mode 

    str returns an empty string, and the status code is 0.


    BuildRequest:
    Qt Code:
    1. QUrl req("https://mws.amazonservices.co.uk");
    2.  
    3. QUrlQuery q;
    4.  
    5. q.addQueryItem("AWSAccessKeyId", AccessKey);
    6. q.addQueryItem("Action", action);
    7. q.addQueryItem("Merchant", MerchantID);
    8. q.addQueryItem("SignatureVersion", "2");
    9. q.addQueryItem("Timestamp", Timestamp.toString());
    10. q.addQueryItem("Version", "2009-01-01");
    11. q.addQueryItem("Signature", Signature);
    12. q.addQueryItem("SignatureMethod", "HmacSHA256");
    13. q.addQueryItem("FeedType", type);
    14. q.addQueryItem("MarketplaceIdList.Id." + MarketplaceListID, marketplace.value("MarketplaceID").toString());
    15. q.addQueryItem("PurgeAndReplace", "false");
    16.  
    17. req.setQuery(q);
    18. return req;
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by ChrisW67 View Post
    What does "XML 1st line" even mean?
    I just want to send the XML 1st line (the XML declaration) to Amazon, for testing purposes.
    Last edited by Poonarge; 8th July 2014 at 09:40.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Send XML 1st line to Amazon

    Aside from your content type header being wrong, have you tried connecting to the QNetworkReply's signals, especially the error signal?
    Does this require authentication?

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    Poonarge (10th July 2014)

  7. #6
    Join Date
    Jun 2014
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Send XML 1st line to Amazon

    Just changed the content type header to text/xml, which I assume is correct?
    Also just connected to the error signal, it returned an UnknownContentError(299)?
    In my current code, I am not sending the XML, which is something I am having trouble with as I don't know how.
    Last edited by Poonarge; 8th July 2014 at 12:28.

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Send XML 1st line to Amazon

    The XML, which you have to actually put at least an empty top level element in, should be passed as the body of the request using the second argument of the post() function. You are trying to mix a content type of urlencoded data and the xml data: this will not work.

    It is unlikely the value you are putting in the Content-md5 header is correct. You are base 64 encoding a hex string.

  9. #8
    Join Date
    Jun 2014
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Send XML 1st line to Amazon

    Thanks, So it should be more like this:

    Qt Code:
    1. QNetworkReply * reply = test.post(request, XML);
    To copy to clipboard, switch view to plain text mode 

    I thought POST parameters were sent as body content though? or is that not the case?
    I will try to implement what you said now.

    UPDATE:

    Have made said changes, although I'm getting a 302 error - Bad Request. Still a bit unsure on the Content-MD5 too.

    Regards,

    Richard
    Last edited by Poonarge; 9th July 2014 at 11:42.

  10. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Send XML 1st line to Amazon

    If the service is expecting URL endoded form values then you send them as the body and set the Content-Type to application/x-www-form-urlencoded.
    If the service is expecting a request in some XML form, e.g. as SOAP request, then you send that as the body and Content-Type to application/soap+xml or text/xml depending on the exact service.
    It's also possible the service is expecting something encoded as multipart/form-data, but that seems unlikely.

    Amazon MWS looks like the first option (see page 19 here https://images-na.ssl-images-amazon....loperGuide.pdf) so XML has nothing to do with the request. The response is an XML document, see page 22.

  11. #10
    Join Date
    Jun 2014
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Send XML 1st line to Amazon

    I've made a successful request to GetFeedSubmissionList, which is fine as I'm not required to send XML for that call. But when I need to submit a feed, I have to send XML.

    Example:
    Amazon Scratchpad - HTTP POST

    Qt Code:
    1. POST /?AWSAccessKeyId=XXXXXXXXXXXXXXXXXX
    2. &Action=SubmitFeed
    3. &Merchant=XXXXXXXXXXXXXXXXXX
    4. &SignatureVersion=2
    5. &Timestamp=2014-07-09T11%3A59%3A18Z
    6. &Version=2009-01-01
    7. &Signature=XXXXXXXXXXXXXXXXXX
    8. &SignatureMethod=HmacSHA256
    9. &FeedType=_POST_PRODUCT_DATA_
    10. &MarketplaceIdList.Id.1=XXXXXXXXXXXXXXXXXX
    11. &PurgeAndReplace=false HTTP/1.1
    12. Host: mws.amazonservices.co.uk
    13. x-amazon-user-agent: AmazonJavascriptScratchpad/1.0 (Language=Javascript)
    14. Content-MD5: XXXXXXXXXXXXXXXXXX
    15. Content-Type: text/xml
    To copy to clipboard, switch view to plain text mode 

    I need to then attach my XML to the request somehow.

  12. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Send XML 1st line to Amazon

    As the request body in the second parameter to post()

  13. The following user says thank you to ChrisW67 for this useful post:

    Poonarge (10th July 2014)

  14. #12
    Join Date
    Jun 2014
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Send XML 1st line to Amazon

    Qt Code:
    1. QNetworkAccessManager test;
    2. QEventLoop loop2;
    3.  
    4. connect(&test, SIGNAL(finished(QNetworkReply*)), &loop2, SLOT(quit()));
    5. QNetworkReply * reply = test.post(request, XML);
    6. connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError(QNetworkReply::NetworkError)));
    7. loop2.exec();
    8.  
    9. QString str = reply->readAll();
    To copy to clipboard, switch view to plain text mode 

    str suggests a Server timeout waiting for the HTTP request from the client / Bad Request


    UPDATE:

    All seems to be working great now, thanks for your help.
    Last edited by Poonarge; 10th July 2014 at 12:02.

Similar Threads

  1. HTTPS request returns damaged HTML body
    By ljuhrich in forum Qt Programming
    Replies: 6
    Last Post: 2nd June 2013, 08:37
  2. Replies: 1
    Last Post: 6th February 2013, 12:18
  3. send a special request using AT command
    By baobui in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 13th December 2011, 11:28
  4. send request via ISA PROXY SERVER
    By rmagro in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2010, 22:56
  5. How do I send data with http post request?
    By Morea in forum Qt Programming
    Replies: 13
    Last Post: 21st January 2009, 22:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.