Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Split] Using HTTP for data transfer
Forum Updated to NodeBB v4.3 + New Features

[Split] Using HTTP for data transfer

Scheduled Pinned Locked Moved General and Desktop
23 Posts 5 Posters 10.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pranj51
    wrote on 3 Nov 2011, 07:20 last edited by
    #1

    hi volker,
    I want to design a app using which user would fill in some data ,for example his user id & after he clicks "SEND" button that user id should get transfferd to a specific url(using HTTP protocol). Once it reaches to that respective url some response is sent back to the user.
    I have searched many examples but I am not able to find appropriate application that would explain how to achieve this.
    Can you guide me through this?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 3 Nov 2011, 15:37 last edited by
      #2

      First of all:
      Please do not add completely new questions to an existing thread dealing with another topic, just open a new thread describing your problem. For this I have split off your question to a new thread.

      Regarding your question:
      Have a look at [[Doc:QNetworkAccessmanager]] and its accompanying classes. It provides what you need. Please search DevNet and the forums, countless examples have been posted already. The docs provide you some examples too, as well as the examples and demos included in the Qt sources.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pranj51
        wrote on 4 Nov 2011, 04:10 last edited by
        #3

        Thank you volker for your reply.
        I couldnt start a new thread as I coudnt find a link anywhere to do so. thats the reason I posted my question on the previous thread itself.
        it would be really great if you can tell me how to start a new thread.

        1 Reply Last reply
        0
        • E Offline
          E Offline
          Eddy
          wrote on 4 Nov 2011, 04:18 last edited by
          #4

          Go to the link "forum" on top of this page. This will open another page with all the subforums. Pick one by clicking on it.
          In the subforum you get a green button to start a new topic.

          Also "this help page":http://developer.qt.nokia.com/wiki/ForumHelp might help you.

          Cheers

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pranj51
            wrote on 4 Nov 2011, 05:13 last edited by
            #5

            I need my program to post some values that exist in key->value pair in my url in the log file thats stored on the server.all the examples that I see are for uploading a file or downloading a file from server.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kxyu
              wrote on 4 Nov 2011, 05:59 last edited by
              #6

              You should search better. All you need is to send a POST request with your data inside in some format (e.g. JSON) and then read the reply.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pranj51
                wrote on 4 Nov 2011, 06:42 last edited by
                #7

                Hii i have found a example that somehow resembles my requirements.
                but the problem now is that I am not able to include header file <QNetworkAccessManager> in my program. the application is giving error "No such File or Directory".
                what can be the actual problem?

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pranj51
                  wrote on 4 Nov 2011, 07:03 last edited by
                  #8

                  hiii,
                  I am trying to write a program that can send request using parametrized URL , for that purpose I am trying to include <QNetworkAccessManager.h> header file but the application is giving error as "No such file or directory".
                  Am I doing some mistakes?
                  How can I include this header file in my application?

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JohanSolo
                    wrote on 4 Nov 2011, 07:17 last edited by JohanSolo 5 Nov 2015, 07:25
                    #9

                    Don't use the '.h', instead do :
                    #include <QtNetwork/QNetworkManager>
                    And don't forget to add

                    QT += network
                    

                    in your .pro file.

                    `They did not know it was impossible, so they did it.'
                    -- Mark Twain

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      Kxyu
                      wrote on 4 Nov 2011, 07:27 last edited by
                      #10

                      try <QtNetwork/QNetworkAccessManager>. don't forget to link network module to yout project

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pranj51
                        wrote on 4 Nov 2011, 08:12 last edited by
                        #11

                        I linked the network module to my .pro file nw the header file is getting included...thank u Kxyu!!

                        I have written a very simple program to post parameters in 'key->value' pair using 'connect_server' slot but the values are not getting posted on the server for some strange reasons. Following is my code,can you tell me what is the mistake in it?

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          pranj51
                          wrote on 4 Nov 2011, 08:12 last edited by
                          #12

                          @
                          #include "mynetclass.h"
                          #include "ui_mynetclass.h"

                          mynetclass::mynetclass(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::mynetclass)
                          {

                          ui->setupUi(this);

                          connect_server();

                          }

                          mynetclass::~mynetclass()
                          {
                          delete ui;
                          }

                          void mynetclass::connect_server()
                          {
                          QNetworkAccessManager *manager = new QNetworkAccessManager();

                          QString strurl= "http://anush/alva/SlCustomObject_AndroidCalls?Param_one=Pranj& Param_two=51\\anush\nj_logs\salva";
                          

                          QUrl url( strurl, QUrl::TolerantMode );

                          QNetworkRequest request;

                          request.setUrl(url);

                          manager->post(request,url.encodedQuery());
                          

                          }
                          @

                          [EDIT: code formatting, please wrap in @-tags, Volker]

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on 4 Nov 2011, 12:18 last edited by
                            #13

                            Merged in the questions for your other thread. Please don't spread the same questions over multiple threads.

                            And please use the code formatting for your source snippets, either by using the code format button in the editor, or by adding @-tags manually.

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply
                            0
                            • K Offline
                              K Offline
                              Kxyu
                              wrote on 4 Nov 2011, 15:15 last edited by
                              #14

                              So how do you check if the data has been sent? if it's some kind of server-side script, I think we need its code too

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                goetz
                                wrote on 4 Nov 2011, 15:31 last edited by
                                #15

                                You send the parameters twice (as parameters to the URL and as post payload).

                                And now, if you did tell us what happens on the server side (or what not and what you've expected), we could be of a little bit more help.

                                Please read and understand http://www.catb.org/~esr/faqs/smart-questions.html - by providing meaningful information (and not only a dump of some C++ code without comments) you're more likely to get useful answers.

                                http://www.catb.org/~esr/faqs/smart-questions.html

                                1 Reply Last reply
                                0
                                • P Offline
                                  P Offline
                                  pranj51
                                  wrote on 7 Nov 2011, 06:30 last edited by
                                  #16

                                  hii kxyu!!
                                  As you have asked for the server-side code,This is the servlet on the server side with wich I am trying to communicate through my code.

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    pranj51
                                    wrote on 7 Nov 2011, 06:52 last edited by
                                    #17

                                    @
                                    import javax.servlet.ServletConfig;
                                    import javax.servlet.ServletException;
                                    import javax.servlet.http.HttpServlet;
                                    import javax.servlet.http.HttpServletRequest;
                                    import javax.servlet.http.HttpServletResponse;
                                    import java.io.IOException;

                                    public class SlCustomObject_AndroidCalls extends HttpServlet
                                    {

                                    public void init(ServletConfig config) throws ServletException
                                    {
                                    try
                                    {
                                    super.init(config);
                                    }
                                    catch(Exception e){Logger.toLog("Android ","SlCustomObject_AndroidCalls","init: Exception " + e);}
                                    }

                                    public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
                                    {

                                    try
                                    {

                                                  doPost(req,res);
                                    

                                    }

                                                 catch(Exception e)
                                    

                                    {

                                                 Logger.toLog("Android ","SlCustomObject_AndroidCalls","doGet: Exception "+e);
                                    

                                    }

                                    }

                                    public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException

                                    {

                                    try

                                    {

                                          String stParam_one="";
                                          String stParam_two="";
                                    

                                    if(req.getParameter("Param_one")!=null)

                                             {
                                                              
                                                   stParam_one = req.getParameter("Param_one").toString().trim();
                                       
                                             
                                             }
                                    

                                    if(req.getParameter("Param_two")!=null)

                                        {
                                                     
                                                  stParam_two = req.getParameter("Param_two").toString().trim();
                                            
                                        }
                                    

                                    Logger.toLog("Android ","SlCustomObject_AndroidCalls","**** Call In Servlet ******");

                                    Logger.toLog("Android ","SlCustomObject_AndroidCalls","stParam_one: "+stParam_one+" stParam_two: "+stParam_two);

                                    }

                                    catch(Exception e) {}

                                    }//end of doPost() method
                                    }//End of SlLogin servlet
                                    @

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      goetz
                                      wrote on 7 Nov 2011, 09:51 last edited by
                                      #18

                                      That's nicely formatted and indented code with a sweet bunch of empty lines that we all love to look at...

                                      Sorry, but do you really expect answers from that? At least a hint, what's in your sever logs would be of help.

                                      You've been told what to do and what to write multiple times now, so I'm out here from this point. I'm not convinced you deserve any help after being that "cooperative", sorry. I'm not after that you give me a single bit and I have to subserviently beg for another little piece of information.

                                      Please read and understand http://www.catb.org/~esr/faqs/smart-questions.html

                                      http://www.catb.org/~esr/faqs/smart-questions.html

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        pranj51
                                        wrote on 8 Nov 2011, 06:15 last edited by
                                        #19

                                        Hello Volker...
                                        This is for the first time that I am communicating my queries to any expert on a forum,so please forgive me if my way of questioning have caused any inconvenience to you..
                                        I'll take care that I provide sufficient information before posting my queries.

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          goetz
                                          wrote on 10 Nov 2011, 02:11 last edited by
                                          #20

                                          Ok, so you're new to these kind of media, which explains things. Just some tips for the future, which make it much more likely that you get meaningful answers:

                                          • always remember, that the readers in a forum do know nothing about your project, so give decent background information
                                          • describe what you want to achieve, how you implement it and what is the result (in your case: what arrives (and what not) at the Java server side)
                                          • if you post code, boil it down to the absolute minimum, leave out stuff that does not "contribute" to the problem

                                          http://www.catb.org/~esr/faqs/smart-questions.html has some more tips for behaving "nicely".

                                          So, for your current problem:
                                          what arrives (and what not) at the Java server side?

                                          http://www.catb.org/~esr/faqs/smart-questions.html

                                          1 Reply Last reply
                                          0

                                          1/23

                                          3 Nov 2011, 07:20

                                          • Login

                                          • Login or register to search.
                                          1 out of 23
                                          • First post
                                            1/23
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved