1
0
mirror of https://github.com/arduino-libraries/ArduinoHttpClient.git synced 2025-06-11 17:08:08 +03:00

Updated to new API as discussed on the Arduino Developers mailing list. Part of the process of moving the library to live as one of the core Arduino libraries.

The get/put/post calls have been streamlined to require fewer parameters in the basic case - i.e. you can just call http.get("www.mysite.com", "/somepath") to make a simple request.

The accept header has been removed from the list of possible parameters to get/put/post - if you need to use it then send it manually with sendHeader(...) instead.

You don't need to call finishRequest() after the initial call to get/put/post if you aren't going to send any headers.  However, if you /do/ want to send extra headers then you need to call beginRequest() before the get/put/post and endRequest() at the end of all the sent data (so after the data as well as the headers).  E.g.

	http.beginRequest();
	http.post("www.somesite.com", "/somepath");
	http.sendHeader("Content-Length", strlen(postdata));
	http.print(postdata);
	http.endRequest();
This commit is contained in:
amcewen
2012-03-30 15:11:13 +01:00
parent 222f718705
commit 44d790b8a6
7 changed files with 323 additions and 144 deletions

View File

@ -1,4 +1,4 @@
// (c) Copyright 2010-2011 MCQN Ltd.
// (c) Copyright 2010-2012 MCQN Ltd.
// Released under Apache License, version 2.0
//
// Simple example to show how to use the HttpClient library
@ -7,17 +7,16 @@
#include <SPI.h>
#include <HttpClient.h>
#include <b64.h>
#include <Ethernet.h>
#include <EthernetClient.h>
// This example downloads the URL "http://arduino.cc/"
// Name of the server we want to connect to
char* kHostname = "arduino.cc";
const char kHostname[] = "arduino.cc";
// Path to download (this is the bit after the hostname in the URL
// that you want to download
const char* kPath = "/";
const char kPath[] = "/";
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
@ -33,9 +32,7 @@ void setup()
while (Ethernet.begin(mac) != 1)
{
#ifdef LOGGING
Serial.println("Error getting IP address via DHCP, trying again...");
#endif
delay(15000);
}
}
@ -47,13 +44,11 @@ void loop()
EthernetClient c;
HttpClient http(c);
err = http.get(kHostname, 80, kPath);
err = http.get(kHostname, kPath);
if (err == 0)
{
Serial.println("startedRequest ok");
http.finishRequest();
err = http.responseStatusCode();
if (err >= 0)
{