WIZnet Developer Forum

Http Post request

I saw the example give on the webclient. it is using http get instead of post.
i want to the arduino uno + wizfi shield to send data to the carriots. Can i get some guide on http post for webclient?

There is HTTP-PUT example as below.
Even though it’s not HTTP-POST, I believe that you can refer it.

https://github.com/Wiznet/Arduino_WizFi250/blob/master/Software/WizFi250/Examples/WizFi250XivelyClient/WizFi250XivelyClient.ino

Hi,

This is the example for webclient using http post.
Ubidots.com” offer this example. http://ubidots.com/docs/devices/wizfi.html#devices-arduino-wiznet
But, source code was little modified.

//------------------------------------------------------------------------------------------------
 /*
  Simple example using WizFi device

  This example was made using an example of the original library and was modified to work with tje Ubidots platform.

  This sketch connects to Ubidots (http://www.ubidots.com) using an WizNet Shield

  Components:
  * WizFi Hardware
  * Arduino UNO
  * WizFi250 library

  Modified 15 Sep 2014
  by Mateo Vélez - Metavix - for Ubidots Inc.

  This code is in the public domain.

  */
// Modified by Daniel

#include <Arduino.h>
#include <SPI.h>
#include "WizFi250.h"
#include "WizFi250_tcp_client.h"


#define SSID  "iptime"
#define KEY ""
#define AUTH  "OPEN"

#define  REMOTE_PORT    80
#define  LOCAL_PORT     5004

IPAddress destIP  (50,23,124,68);                  //ip of the server


WizFi250    wizfi250;
WizFi250_TCP_Client myClient;

boolean Wifi_setup = false;


//The setup function is called once at startup of the sketch
void setup()
{
// Add your initialization code here
  Serial.begin(9600);
  Serial.println("\r\nSerial Init");

  wizfi250.begin();
  wizfi250.setDebugPrint(4);
  wizfi250.hw_reset();

  wizfi250.sync();
  wizfi250.setDhcp();

  for(int i=0; i<10; i++)
  {
    if( wizfi250.join(SSID,KEY,AUTH) == RET_OK )
    {
      Wifi_setup = true;
      break;
    }
  }
}


void loop()
{
//Add your repeated code here
  uint8_t retval=0, len=0;
  uint8_t ch;
  uint8_t Txbuf[250];
        int data = analogRead(A0);
        char post_data_buf[32];
        snprintf(post_data_buf, sizeof(post_data_buf), "{\"value\": %d}\r\n", data);
  if( Wifi_setup )
  {
    wizfi250.RcvPacket();

    if( myClient.available() )
    {
      ch = myClient.recv();
      if(ch != NULL)
        Serial.print((char)ch);
    }
    else
    {
      myClient = WizFi250_TCP_Client(destIP, REMOTE_PORT);
      retval = myClient.connect();

      if(retval == RET_OK)
      {
      //change the "xxxxx..."" with your variable id and "yyyy..." with your token
        Serial.println("Connected! ");
        sprintf((char*)Txbuf,"POST /api/v1.6/variables/xxxxxxxxxxxxxxxxx/values HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: %d\r\nX-Auth-Token: yyyyyyyyyyyyyyyyyyy\r\nHost: things.ubidots.com\r\n\r\n%s\r\n",strlen(post_data_buf),post_data_buf);
        myClient.send((uint8_t*)Txbuf,sizeof(Txbuf));
        Serial.println((char*)Txbuf);
      }
    }
  }
}

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.