Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29

Thread: Reqest and Response in XML

  1. #21
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Reqest and Response in XML

    I getting "Unknown error" as the output for the error string, when i use it in the fetch function

    But when i use it in the finished function, am getting "Authentication required".

    But i am passing the username and password in the variable converted under http.setUser.

    any ideas as to what might be the problem??

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reqest and Response in XML

    Use a network sniffer to see how your request looks like when it leaves your network interface. See if the proper auth data is contained in the http request.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #23
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Reqest and Response in XML

    i used the network sniffer

    here is what i got, in packets

    Qt Code:
    1. [B]HOST[/B]
    2.  
    3. .à ügÇT.¡„Ï3ˆd.>/.!E.-ú@.€JT;\*I®…R\.P²4Þ¼*·}ÓPÿÿ)¥..POST /api/ HTTP/1.1
    4. Connection: Keep-Alive
    5. Host: ionlab.webfactional.com
    6. content-length: 162
    7.  
    8. <request version="0.1" >
    9. <call name="teci.client.create" >
    10. <client>
    11. <kind>MOBILE</kind>
    12. <name>API Test suite 7936</name>
    13. </client>
    14. </call>
    15. </request>
    16.  
    17.  
    18. [B]SERVER[/B]
    19.  
    20. .¡„Ï3.à ügÇTˆd.>D.!E.B“i@.6Ю…R;\*I.P\*·}Ó²4ßÁP Z..HTTP/1.1 401 Authorization Required
    21. Server: nginx
    22. Date: Thu, 02 Jul 2009 14:41:37 GMT
    23. Content-Type: text/html; charset=utf-8
    24. Transfer-Encoding: chunked
    25. Connection: keep-alive
    26. Vary: Cookie
    27. WWW-Authenticate: Basic realm="TrackEveryCoin API"
    28.  
    29. 16
    30. Authorization Required
    31. 0
    32.  
    33. [B]HOST[/B]
    34.  
    35. .à ügÇT.¡„Ï3ˆd.>Å .!E.ˆÿ@.€Iô;\*I®…R\.P²4ßÁ*·~Ã*Pþå¾I..POST /api/ HTTP/1.1
    36. Connection: Keep-Alive
    37. Host: ionlab.webfactional.com
    38. content-length: 162
    39. Authorization: Basic QXV0aG9yaXphdGlvbiA6IGMzSnZhR2wwTWpSQVoyMWhhV3d1WTI5dE9qRXlNelExOg==
    40.  
    41. <request version="0.1" >
    42. <call name="teci.client.create" >
    43. <client>
    44. <kind>MOBILE</kind>
    45. <name>API Test suite 7936</name>
    46. </client>
    47. </call>
    48. </request>
    49.  
    50.  
    51. [B]SERVER[/B]
    52.  
    53. .¡„Ï3.à ügÇTˆd.>D.!E.B“j@.6Ï®…R;\*I.P\*·~Ã*²4á!PPSk..HTTP/1.1 401 Authorization Required
    54. Server: nginx
    55. Date: Thu, 02 Jul 2009 14:41:37 GMT
    56. Content-Type: text/html; charset=ut-8
    57. Transfer-Encoding: chunked
    58. Connection: keep-alive
    59. Vary: Cookie
    60. WWW-Authenticate: Basic realm="TrackEveryCoin API"
    61.  
    62. 16
    63. Authorization Required
    64. 0
    To copy to clipboard, switch view to plain text mode 

    Before the complete data is being sent, i am getting the authentication required error

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reqest and Response in XML

    You are not sending the authentication data. Make sure you use setUser() early enough in the flow. Also consider switching from QHttp to QNetworkAccessManager, it's easier to use it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #25
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Reqest and Response in XML

    i got it working mate. thanks for ur help

    here is the code that works

    Qt Code:
    1. void RSSListing::fetch()
    2. {
    3. lineEdit->setReadOnly(true);
    4. fetchButton->setEnabled(false);
    5. abortButton->setEnabled(true);
    6. treeWidget->clear();
    7. xml.clear();
    8.  
    9. QByteArray string ("username");
    10. string.append(":");
    11. string.append("12345");
    12. QString encoded = string.toBase64();
    13. qDebug() <<"String"<< string <<"Encoded" <<encoded ;
    14.  
    15. QUrl url("something/api/");
    16. url.setUserName("username");
    17. url.setPassword("12345");
    18.  
    19. QHttpRequestHeader header("POST","/api/");
    20. header.setValue("Host",url.host());
    21. header.setValue("Path",url.path());
    22. header.setValue("Authorization","Basic " + encoded);
    23.  
    24. http.setHost(url.host(),url.port(80));
    25.  
    26. sendrequest();
    27. connectionId = http.request(header,xmlrequest);
    28. }
    To copy to clipboard, switch view to plain text mode 

    I am getting the response as per the specifications.

    While parsing, is it possible to go to a particular tag, say skip the 1st 3 tags and go directly to the 4th one?

    The first few tags in the response is redundant, i dont want to waste time parsing through them.

    thanks
    Last edited by srohit24; 3rd July 2009 at 12:43.

  6. #26
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Reqest and Response in XML

    My parsing code is this.

    Qt Code:
    1. void MainWindow::parseXml()
    2. {
    3.  
    4. while (!xml.atEnd())
    5. {
    6. xml.readNext();
    7.  
    8. if (xml.isStartElement())
    9. {
    10. currentTag = xml.name().toString();
    11. qDebug() << "Current tag"<< currentTag ;
    12.  
    13. }
    14. else if (xml.isEndElement())
    15. {
    16. if (xml.name() == "response")
    17. {
    18.  
    19. item->setText(0, titleString);
    20. item->setText(1, linkString);
    21. treeWidget->addTopLevelItem(item);
    22.  
    23. titleString.clear();
    24. linkString.clear();
    25. }
    26.  
    27. }
    28. else if (xml.isCharacters() && !xml.isWhitespace())
    29. {
    30. if (currentTag == "client")
    31. titleString += xml.attributes().value("id").toString();
    32. else if (currentTag == "serial_number")
    33. linkString += xml.text().toString();
    34. }
    35. }
    36. if (xml.error() && xml.error() != QXmlStreamReader::PrematureEndOfDocumentError) {
    37. qWarning() << "XML ERROR:" << xml.lineNumber() << ": " << xml.errorString();
    38. http.abort();
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. <response version="0.1">
    2. <client id="1">
    3. <name>API Test suite 7936</name>
    4. <kind>MOBILE</kind>
    5. <serial_number>a09b4d3b-08b7-4cdf-bf3c-a5a8fb27ee1f</serial_number>
    6. <added_on>2009-06-25 12:33:49.182287</added_on>
    7. <enabled>True</enabled>
    8. </client>
    9. </response>
    To copy to clipboard, switch view to plain text mode 

    I am able to get the serial no from the response, but to get the value of id in client tag is proving hard.

    how can i get the value from a attribute and convert it into string??

  7. #27
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reqest and Response in XML

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #28
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Reqest and Response in XML

    thanks mate.

    I was trying to find the tag when it was already parsed. Fixed it. working now.

    Can you tell me a method through which i can go directly to a particular tag in the QXMLStreamHeader??

    I want to skip the 1st 3 tags and go directly to the 4th one.

  9. #29
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reqest and Response in XML

    Consider using QDomDocument instead of the stream reader. It is easier to manipulate the xml there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Tags for this Thread

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.