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:
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&text=%s&outputMode=%s","31adba6dfc3a879b88762f50efc9f892bd573207", "i+feel+great", "json");
Serial.println(request);
When I print the request, everything after the & 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.
-
2How is "request" defined?Majenko– Majenko2015年05月12日 17:33:27 +00:00Commented May 12, 2015 at 17:33
1 Answer 1
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.