Open long url

Hi I have a problem with Arduino, I can’t open an URL (with GET) if the parameter of the URL is too long!
example:
GET www.example.com/foo.php?bar=123 → OK
GET www.example.com/foo.php?bar=1234567890...1234567890 → KO =(
I don’t have any error, it’s just stuck and it doesn’t do the http get

with too long I mean the output of an RC4 encryption encoded in Hexadecimal, which is about 60 characters!
here it is the code of the http GET:

    char cip[60]; 
    enc.toCharArray(cip,60); //enc is the String encrypted and coded in hex
    char url[] = "GET /foo.php?bar=";
    strcat(url,cip);
    strcat(url," HTTP/1.1");
    client.println(url);
    client.println("Host: www.example.com");
    client.println("Connection: close");
    client.println();

Can you help me? :smiley:
Thank you in advance

    char url[] = "GET /foo.php?bar=";
    strcat(url,cip);
    strcat(url," HTTP/1.1");

url only has space for 17 characters plus the null-terminator. If you want to concatenate strings on top of that, you need to be explicit about the size of url and give it enough room for the concatenations.

Thank you for the reply, the old problem seems fixed, but now I have another one:
I changed the code to this (I have used the exact length only for the example):

    char cip[60];
    enc.toCharArray(cip,60);
    char url[102];
    strcpy(url, "GET /foo.php?bar=");
    strcat(url,cip);
    strcat(url," HTTP/1.1");

now I got from the server:

<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.

</p>
</body></html>

Maybe is there an error in the url?

It's probably a good idea to print to the serial monitor, what you are sending to the server.

obviously I use the serial monitor but the problem is that the URL seems ok... :frowning:

daniele2010:
obviously I use the serial monitor

Wasn’t in your original code, so apparently, it’s not THAT obvious.

but the problem is that the URL seems ok… :frowning:

Because it’s not, and you’ve only chose to put snippits of code, so you’re only getting snippits of answers.

Shouldn't you have some line feeds in that HTTP request?

Arrch:

daniele2010:
obviously I use the serial monitor

Wasn’t in your original code, so apparently, it’s not THAT obvious.

but the problem is that the URL seems ok… :frowning:

Because it’s not, and you’ve only chose to put snippits of code, so you’re only getting snippits of answers.

It wasn’t a tease, I mean that the use of the Serial monitor is natural if I ask for help. I put the whole url variable in the Serial and the url is correct, I also put a delimeter “|” to check where it starts and where it ends but it seems ok…

PeterH:
Shouldn’t you have some line feeds in that HTTP request?

where should I have it? At the end?

daniele2010:
where should I have it? At the end?

Look at the format of an HTTP request, either by looking at the protocol specification or by looking at example HTTP client sketches. The request consists of multiple lines of text separate by line feeds. For example, the GET and HTTP parts of the request should be on separate lines. The web server uses the line feeds to parse the request; if you leave them out, it won't be able to make sense of the request.

why not client.print the parts of the URL directly?

    char cip[60]; 
    enc.toCharArray(cip,60); //enc is the String encrypted and coded in hex

    client.print("GET /foo.php?bar=");  // optionally use the F() macro
    client.print(cip);
    client.println(" HTTP/1.1");

    client.println("Host: www.example.com");
    client.println("Connection: close");
    client.println();

Thank you for all replies, I fixed the RC4 encryption with base64 encoding and now it works without any problem (base64 is more expressive than hex so I need less characters) :slight_smile: