1

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&outputMode=json&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&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.

jfpoilpret
9,1627 gold badges38 silver badges54 bronze badges
asked May 12, 2015 at 17:09
1
  • 2
    How is "request" defined? Commented May 12, 2015 at 17:33

1 Answer 1

0

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.

answered May 12, 2015 at 23:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.