How to clear http GET requests

I’ve been successfully using http GETs on several projects but have not been able to get rid of the request in the URL line without using a button as per the example below.

Can someone advise a line of code that I can replace the Clear button with that will just remove the GET request?

//
//
// Trying to clear Gets:
//
//


// Libraries

//Ethernet Libraries and Settings
#include <SPI.h>
#include <Ethernet.h>
//Set unique MAC address
byte mac[] = { 0x01, 0x01, 0x01, 0x01, 0xFE, 0xEA };
//Set IP address
byte ip[] = { 192, 168, 0, 121 };
EthernetServer server(80);


String readString = ""; // Used to store Form value
int    CircuitPin = 5;  // pin to turn on and off



void setup()
{
  // setup ethernet
  Ethernet.begin(mac, ip);
  server.begin();

  digitalWrite(CircuitPin, HIGH);

}



void doreadStringAction()
{

  if (readString.indexOf("?circon") > 0)
  {
    digitalWrite(CircuitPin, HIGH);   //turn on the output
  }

  if (readString.indexOf("?circoff") > 0)
  {
    digitalWrite(CircuitPin, LOW);    //turn off the output
  }
}




void loop() {

  // listen for incoming clients
  EthernetClient client = server.available();
  if ( client )  // then send html to web page
  {
    while (client.connected())
    {
      if (client.available())
      { // start up the server and get string
        char c = client.read();
        if (readString.length() < 100)
        {
          readString += c;
        }
        if (c == '\n')
        {

          client.println("<HTTP/1.1 200 OK>");
          client.println("<Content-Type: text/html>");
          client.println("<html>");
          client.println();

          // send head
          client.print("<head>");
          client.print("<title>Test Page</title>");
          client.println("<meta http-equiv=\"refresh\" content=\"2\">"); // This is used to refresh the page
          client.print("</head>");

          // send body
          client.print("<body>");
          client.println();


          // page header
          client.println("<h3>Web Test</h3>");


          if ( digitalRead(CircuitPin) == LOW ) {
            client.println("OFF");
          }
          else {
            client.println("ON");
          }

          client.println("
");

          client.print("<INPUT type=button value=OFF onClick=window.location='/?circoff'>");
          client.print("<INPUT type=button value=ON onClick=window.location='/?circon'>");

          client.println("
");

          //test to see if we need to do string
          if (readString.indexOf("?circ") > 0) {   //contains the front part of our request
            doreadStringAction();

            //reset string request  ***find a way do do without a button
            client.print("<input type=button value=\"CLEAR\" onClick=window.location=\'/\'>");
          }

          //clear string for next read
          readString = "";

          client.stop();
        }
      }
    }
  }

  delay(100);

}

I’ve tried a variety of js and html commands to do this but am embarrassed to include them here as I clearly don’t know what I’m doing!

Any help would be appreciated.

but have not been able to get rid of the request in the URL line without using a button as per the example below.

You need to explain what “the URL line” means to you.

The URL line is the address bar of the connected web browser.

When you go to the page http://192.168.0.121 that's what you see in the "URL line."

When you push the ON button, you see http://192.168.0.121/?circon (which then gets loaded into the readString and causes the action, i.e. set an output pin as in my code).

I want to clear out the ?circon once the action is done. My CLEAR button will do that, but I don't want to have to push a button, I just want a line of code to do that.

Bump - someone ought to be able to answer this simple question - Help me!!!

Get requests are very handy as any client accessing the page can assert a command just by tacking the request on to the page address, they don't have to necessarily be initiated by a user clicking a button.

But either way a request is initiated, having the arduino remove the request upon completing it would make this a much better solution.

"I want to clear out the ?circon once the action is done. My CLEAR button will do that, but I don't want to have to push a button, I just want a line of code to do that."

Well, it is hard to picture your particular situation using URLs in a browser address bar, but with IE as the browser, you can use the address bar drop down function to select a new URL like in the attached picture. Browsers function the way they are built, so they may not be built to do what you want to do. You probably need to explain just what you are trying to do beyond just clearing the browser address bar. Perhaps the web page you are sending to the browser is not functioning as you expect?

URL.jpg

URL.jpg

zoomkat:
it is hard to picture your particular situation using URLs in a browser address bar

Thank you zoomkat for your reply. I guess I thought readers would look at the code to see what I was trying to do, but see that I need to be more explicit.

This script displays a simple web page at a specific url (it’s ip), the page has an ON and an OFF button and reports the status of an output pin controlled by those buttons.

When the browser user selects an action, that is added to the url, for example, the OFF button is pushed in this code and the address bar will read http://192.168.0.121/?circoff. Then the code tests for that GET value and does the appropriate action.

If the action is called, in addition to changing the pin, it should reset the window.location.href to http://192.168.0.121 sans the “/?circoff” but I am unable to come up with a way to do this. What I can do is create a CLEAR button that does what I need, but I don’t want a user to have to push a button.

onandoff.jpg

"If the action is called, in addition to changing the pin, it should reset the window.location.href to http://192.168.0.121 sans the "/?circoff" but I am unable to come up with a way to do this. What I can do is create a CLEAR button that does what I need, but I don't want a user to have to push a button."

The browser is probably going to retain the last URL request sent in the address bar. This may have to do with the function of the browser refresh button. You might add a meta refresh function in the page code set to 0 to refresh to 192.168.0.121 without the /?circoff query string.

zoomkat:
You might add a meta refresh function in the page code set to 0 to refresh to 192.168.0.121 without the /?circoff query string.

Thanks, but I don't understand your suggestion. My script already calls meta refresh which doesn't affect the address. Also, I don't see anything like a "page code" for that call per HTML meta http-equiv Attribute

you can transmit your data as POST request instead as GET request.
In this case the payload is transmitted in the http body and not appended to the URI.
The browser address field will show only the URI, no parameters.

So basically, there is no need to "clear" anything - just use the right http method.

"Thanks, but I don't understand your suggestion."

It is a redirect refresh as demonstrated in the below link. Set the time to 0.

noiasca:
you can transmit your data as POST request instead as GET request.

Thanks for the suggestion noiasca, but I need to use a GET because as I explained above, I want clients to be able to send the commands through the address bar without a user having to click a button.

zoomkat:
It is a redirect refresh as demonstrated in the below link. Set the time to 0.

Ah, now I understand. That WORKS! Thank you.