Results 1 to 1 of 1

Thread: Query about setProxy() function

  1. #1
    Join Date
    Feb 2011
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Query about setProxy() function

    Hello,

    I have some problem in using qt setProxy() function.
    I have to download file from a http server which I have installed on another system .
    I have installed apache2 server and squid proxy server installed on that system.

    what address should i provide for setproxy() function and what port.

    How can I know that my code is working or not.

    Here is my code.
    Qt Code:
    1. //*******http.cpp*******
    2.  
    3.  
    4. #include "http.h"
    5. //#include <iostream>
    6. #include<dirent.h>
    7. #include<QDir>
    8.  
    9. //using namespace std;
    10.  
    11. http::http(QWidget *parent)
    12. : QMainWindow(parent)
    13. {
    14. }
    15.  
    16. http::~http()
    17. {
    18.  
    19. }
    20.  
    21. HttpGet::HttpGet(QObject *parent)
    22. : QObject(parent)
    23. {
    24. connect(&http, SIGNAL(done(bool)), this, SLOT(HttpDone(bool)));
    25. }
    26.  
    27. bool HttpGet::getFile(const QUrl &url)
    28. {
    29.  
    30. QString str = QDir::currentPath();
    31. QDir::setCurrent(str+"/Downloads");
    32.  
    33.  
    34. if (!url.isValid()) {
    35. cerr << "Error: Invalid URL" << endl;
    36. return false;
    37. }
    38. else
    39. {
    40. cout << "URL valid..!!" << endl;
    41. }
    42.  
    43. if (url.scheme() != "http") {
    44. cerr << "Error: URL must start with ’http:’" << endl;
    45. return false;
    46. }
    47.  
    48. if (url.path().isEmpty()) {
    49. cerr << "Error: URL has no path" << endl;
    50. return false;
    51. }
    52.  
    53. QString localFileName = QFileInfo(url.path()).fileName();
    54. if (localFileName.isEmpty())
    55. localFileName = "httpget.out";
    56. file.setFileName(localFileName);
    57. if (!file.open(QIODevice::WriteOnly)) {
    58. cerr << "Error: Cannot open " << qPrintable(file.fileName())
    59. << " for writing: " << qPrintable(file.errorString())
    60. << endl;
    61. return false;
    62. }
    63.  
    64. // QNetworkAccessManager *http = new QNetworkAccessManager(this);
    65.  
    66. proxy.setType(QNetworkProxy::Socks5Proxy);
    67. proxy.setHostName("10.0.0.1"); //what address should i provide?
    68. // ip of another comp??
    69. proxy.setPort(8888); //what port??
    70. proxy.setUser("supriya");
    71. proxy.setPassword("supriya");
    72.  
    73. QNetworkProxy::setApplicationProxy(proxy);
    74. http.setProxy(proxy);
    75.  
    76.  
    77. // m_reply = http->get(request);
    78.  
    79. http.setHost(url.host(), url.port());
    80. //cout<< "connected to host" << url.host() << endl << endl;
    81. http.get(url.path(), &file);
    82. http.close();
    83. return true;
    84. }
    85.  
    86. void HttpGet::HttpDone(bool error)
    87. {
    88. if (error) {
    89. cout << "Error: " << qPrintable(http.errorString()) << endl;
    90. } else {
    91. cerr << "File downloaded as " << qPrintable(file.fileName())
    92. << endl;
    93. }
    94. file.close();
    95. emit done();
    96. }
    97.  
    98. //*******main.cpp*******
    99.  
    100. #include <QtGui/QApplication>
    101. #include "http.h"
    102.  
    103. int main(int argc, char *argv[])
    104. {
    105. QCoreApplication app(argc, argv);
    106. QStringList args = app.arguments();
    107. argc=2;
    108. if (argc!= 2) {
    109. cerr << "Usage: httpget url" << endl
    110. << "Example:" << endl
    111. << "httpget http://doc.trolltech.com/qq/index.html"
    112. << endl;
    113. return 1;
    114. }
    115.  
    116. QNetworkProxyFactory::setUseSystemConfiguration(true);
    117.  
    118. HttpGet getter;
    119. if (!getter.getFile(QUrl("http://10.1.11.137:80/"))) //what url?
    120. return 1;
    121. QObject::connect(&getter, SIGNAL(done()), &app, SLOT(quit()));
    122. return app.exec();
    123. }
    To copy to clipboard, switch view to plain text mode 


    when I provide setproxy("10.1.11.137",8888);url = "10.1.11.137:80"

    it gives the output :Http Request failed. I am not getting problem yaar plz plz help me.
    Last edited by sups; 25th March 2011 at 09:09.

Similar Threads

  1. Replies: 2
    Last Post: 13th September 2010, 20:03
  2. Replies: 3
    Last Post: 25th May 2010, 09:46
  3. Replies: 0
    Last Post: 10th March 2010, 08:13
  4. SQL query
    By JD2000 in forum Newbie
    Replies: 4
    Last Post: 1st December 2009, 14:21
  5. MS SQL Query
    By baray98 in forum General Programming
    Replies: 0
    Last Post: 14th July 2009, 04:25

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.