//====================================================================
//  HTTP REQUESTS FROM WEB
//====================================================================
// HTTP Request To Send Data To Server Via WiFi
//--------------------------------------------------------------------

  String prepare_HTTPData(String url, String data) 
  {
    // Just For Display
    Serial.println();
    Serial.println("Sending To AWS Server ------------------------");
    Serial.println();

    // Card Code
    String card = data;

    // fOR TESTING PURPOSES
    //url = "http://rfid.takeone.tech/index.php";

    // PLANNER AWS LINK
    //url += "?json=";

    // COMBINNING INTO JSON DATA MESSAGE
    data = post_json(data);
    
    // Conversion Result
    String ENCODED = base64(data);

    // Serial Print Message
    Serial.println(" -> CARD            : " + card);
    // Printing Data
    Serial.println(" -> JSON DATA       : " + data);

    // New URL
    url += ENCODED;
    
    // Shows Us How It Would Look
    Serial.println(" -> SERVER Request  : " + url);

    // Returnning The Value
    return url;
  }

//--------------------------------------------------------------------
// Send Http Request
//--------------------------------------------------------------------

  String read_payload(String Request) 
  {
    // HTTP Request
    HTTPClient http;

    // Empty PayLoad
    String payload = "";

    // HTTP Status Code
    int httpCode = 0;

    // Transmit Trials Count
    int count = 0;

    do {
      // Counts 
      if(count < 3) {
        count++;
        Serial.println(" -> Trial #" + String(count));
        //ESP.wdtFeed(); // Clearing Watch Dog Timer
      } else {
        break;
      }
      
      // configure traged server and url
      http.begin(Request); //HTTP
      Serial.print("   -> [HTTP] begin GET...\n");
      
      // start connection and send HTTP header
      httpCode = http.GET();
      
      // httpCode will be negative on error
      if(httpCode > 0) {
        // HTTP header has been send and Server response header has been handled
        Serial.printf("   -> [HTTP] GET... code: %d\n", httpCode);
        // file found at server
        if(httpCode == HTTP_CODE_OK) {
          payload = http.getString();
          Serial.println("   -> [HTTP] Response " + payload);
          break;
        }
      } else {
        Serial.printf("   -X [HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        payload = "";
      }
    } while(httpCode != HTTP_CODE_OK);

    // Ending The Http Request
    http.end();

    // Returnning Payload
    return payload;
  }

//--------------------------------------------------------------------
// BASE64 Data Encoding
//--------------------------------------------------------------------

  String base64(String data) 
  {
    // Conversion Object
    rBase64generic<4000> mybase64;
    
    // Encoding The Data
    if (mybase64.encode(data) == RBASE64_STATUS_OK) {
      return mybase64.result();
    } else {
      return "";
    }
  }
