1

I've got a java tomcat servlet with a doPost method and a webpage running on that server. I set up a very basic test with a html button on my web page, that when pressed calls the doPost method. What i would like to know is how i would do this from the arduino? I tried

client.println("POST /Project/index.html?acctID=1234567 HTTP/1.0");

as a means to call the doPost method and pass it an "acctID", this however doesn't call that doPost method. I don't have a very good understanding of how to send get/post from ethernetclient in arduino (i imagine it doesn't work quite how i'm thinking it does), so hopefully someone can help me understand, thanks!

In response to comment:

So i've continued to play with this and what i've done at this point is I've made a server on my java side that sends data (via sockets) to an arduino server that i've made. What i'm trying to do now is send a simple, small piece of data back to my java program/servlet. What i've tried so far that is the code posted above on the arduino side, and on the java side i've got a simple server:

private static void listenForArduino() throws IOException, ClassNotFoundException {
         //static ServerSocket variable
        ServerSocket server;
        //socket server port on which it will listen
        int port = 9876;

      //create the socket server object
        server = new ServerSocket(port);

        //keep listens indefinitely until receives 'exit' call or program terminates
        while(true){
            System.out.println("Waiting for client request...");

            //creating socket and waiting for client connection
            Socket socket = server.accept();

            //read from socket to ObjectInputStream object
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());

            //convert ObjectInputStream object to String
            String message = (String) ois.readObject();
            System.out.println("Message Received: " + message);

            //create ObjectOutputStream object
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());

            //close resources
            ois.close();
            oos.close();
            socket.close();

            //terminate the server if client sends exit request
            if(message.equalsIgnoreCase("exit")) break;
        }

        System.out.println("Shutting down Socket server!!");

        //close the ServerSocket object
        server.close();
    }

I never receive a response, it stalls on this line

server = new ServerSocket(port);

My arduino code (that pertains to this):

if (client.connect(ip, 9876)) {
      Serial.println("connected");
      client.println("POST /NFCPaymentProject/index.html?acctID=1234567 HTTP/1.0");
      client.println();
    } else {
      Serial.println("connection failed");
    }
dks209
  • 57
  • 9
  • Can you add some of the code you have tried? – Jeff Sloyer Apr 13 '15 at 19:00
  • You don't specify post variables in the url, that's usually GET variables, post variables are in the POST body take a look at [this](http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request) and [this](http://stackoverflow.com/questions/7551997/pass-post-data-via-raw-http) – Zachary Craig Apr 14 '15 at 10:17
  • Very helpful links! Thank you! – dks209 Apr 14 '15 at 16:04

0 Answers0