×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Question How to send data with http request through proxy

    Hi everyone,

    I want to send some data using http request through proxy,
    in c++ i usually send it using qnetworkproxy as following;
    QNetworkProxy proxy;
    proxy.setType(QNetworkProxy::HttpProxy);
    proxy.setHostName("thehostname...");
    proxy.setPort(80);

    QString dataa;
    dataa = "myDataToSend";

    nam = new QNetworkAccessManager(this);
    QByteArray myData(dataa.toAscii());
    connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(finishsending(QNetworkReply*)));
    nam->setProxy(proxy);
    nam->post(QNetworkRequest(QUrl("http://.....")),myData);
    i want the same thing with qml but till now i didnt find anything helpfull to accomplish that
    i am sending http request as following , but i need to know how to set the proxy for sending the data!!!
    var req = new XMLHttpRequest();
    req.onreadystatechange = function() {

    if (req.readyState == XMLHttpRequest.DONE) { // 4 instead of 'XMLHttpRequest.DONE' works here too
    console.log("Request complete");

    if (req.status == 200) {
    if(req.responseText != "0")
    {
    console.log("Status code: 200");
    console.log(req.responseText + "...")

    //some functions to do here
    }
    }
    else
    {
    console.log("Status code error: "+req.status+" Unable to connect to internet..");
    }
    }
    }
    req.open("POST","http://......",true);
    req.send("myDataToSend");
    How can i solve my problem
    Thank you
    Rondo

  2. #2
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: How to send data with http request through proxy

    Hi,
    You need to use the network access manager factory.
    Here is an example which show how to use it:
    http://developer.qt.nokia.com/doc/qt...5-c5d8f732b40c

    The full example is here: http://developer.qt.nokia.com/doc/qt...erfactory.html

  3. #3
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Re: How to send data with http request through proxy

    Quote Originally Posted by gnuton View Post
    Hi,
    You need to use the network access manager factory.
    Here is an example which show how to use it:
    http://developer.qt.nokia.com/doc/qt...5-c5d8f732b40c

    The full example is here: http://developer.qt.nokia.com/doc/qt...erfactory.html
    Hi, thank you for your help
    so i should use link between c++ and qml to able to accomplish that ?...
    no direct code from qml will be able to do that?
    since not for all request need to set the proxy...just if the connection is 3g or 4g i need to set a proxy ..and if it is wifi then no need to set a proxy

    Regards,

  4. #4
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: How to send data with http request through proxy

    As far as I know, there is no way to set the proxy in QML.
    Javascript HTTP requests make use of the network access manager.
    In the C++ code you can set or not the proxy accordingly to connection type.

  5. #5
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Re: How to send data with http request through proxy

    Quote Originally Posted by gnuton View Post
    As far as I know, there is no way to set the proxy in QML.
    Javascript HTTP requests make use of the network access manager.
    In the C++ code you can set or not the proxy accordingly to connection type.
    Thank you gnuton for all your clarification
    i will add link between qml and c++ and add the proxy method

    Best Regards,
    Rondo

  6. #6
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: How to send data with http request through proxy

    Good luck Rondoand contact us in case you need more help.
    Some time ago I wrote this article [1].
    If you have time take a look at it. It's short and it explains why we have it and how it works.
    Moreover it shows you how to use proxy.

    [1] http://www.developer.nokia.com/Commu...ManagerFactory

  7. #7
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Re: How to send data with http request through proxy

    Quote Originally Posted by gnuton View Post
    Good luck Rondoand contact us in case you need more help.
    Some time ago I wrote this article [1].
    If you have time take a look at it. It's short and it explains why we have it and how it works.
    Moreover it shows you how to use proxy.

    [1] http://www.developer.nokia.com/Commu...ManagerFactory
    wooww thats a very usefull article..great work gnuton
    thank you for sharing it with me ..u gave me a clarification about things i didnt know
    regards,
    Last edited by Rondo23; 2011-12-01 at 19:53.

Similar Threads

  1. how to send HTTP Request
    By Omnya in forum [Archived] Beginning Qt
    Replies: 13
    Last Post: 2011-02-28, 23:03
  2. How send http request directly?
    By SymbianTH in forum Symbian
    Replies: 3
    Last Post: 2010-04-03, 20:33
  3. How to set proxy in an HTTP request
    By gigglie in forum Symbian
    Replies: 1
    Last Post: 2008-05-23, 10:26
  4. how to send a http request
    By fraysco in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2008-05-12, 17:40
  5. HTTP request via proxy server
    By AndySH in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-11-06, 14:15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×