Wifi REST API GET call - how to concatenate and pass URL parameters? I'm not too familiar with the Arduino C++ language, but I would like to get this native code to work.

In curl this works:


  curl "http://access.alchemyapi.com/calls/text/TextGetTextSentiment?text=i+feel+great&amp;outputMode=json&amp;apikey=my-apikey"^C


So I am trying to use a WiFi client for the same request but it seems the passing and parsing of the URL parameters is causing a problem.

sprintf(request,"/calls/text/TextGetTextSentiment?apikey=%s&amp;text=%s&amp;outputMode=%s","31adba6dfc3a879b88762f50efc9f892bd573207", "i+feel+great", "json");
Serial.println(request);


When I print the request, everything after the &amp; gets truncated.

  char serverName[] = "access.alchemyapi.com";
  if(client.connect(serverName,port) == 1)
  {
    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
  }


This works (HTTP status 200, though with missing parameters error from the API service) if I only pass in 1 parameter.
Concatenating the string data in memory before sending it shouldn't be necessary. Instead, you should just be able to use client.print() (or equivalent) to output each part of the request in sequence. For example:

client.print("GET ");
client.print(page);
client.print(" HTTP/1.1\r\n");

client.print("Host: ");
client.print(serverName);
client.print("\r\n");

// etc.


That should let you output any combination of HTTP headers you need.