Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Status code -3 after two requests in a row #30

Copy link
Copy link
Open
@geovannyAvelar

Description

@geovannyAvelar
Issue body actions

I'm trying to authenticate with my API and send a POST.

void saveWeatherData(WEATHER_DATA data) {
  String jsonData = weatherDataToJson(data);
  Serial.println("Data has been collected");
  Serial.println(jsonData);
  Serial.println("Saving data...");

  HttpClient client = HttpClient(ethernetClient, SERVER_IP, SERVER_PORT);

  String urlAuth = generateAuthenticationUrl("root", "root", "password");
  
  client.beginRequest();
  client.post(urlAuth, "application/json", "");
  client.sendHeader("Authorization", "Basic d2VhdGhlcmxvZ2dlcjp3ZWF0aGVybG9nZ2Vy");
  client.endRequest();

  String token;
  int statusAuth = client.responseStatusCode();

  if(statusAuth == 200) {
      Serial.println("Authentication OK");
      String stringResponse = client.responseBody();

      DynamicJsonBuffer jsonBuffer;
      JsonObject& jsonResponse = jsonBuffer.parseObject(stringResponse);

      token = jsonResponse["access_token"].as<String>();
  } else {
    Serial.write("Error on authentication ");
    Serial.println(statusAuth);
  }

  delay(3000);
  
  String authHeader = "Bearer ";
  authHeader.concat(token);

  client.beginRequest();
  client.post("/", "application/json", jsonData);
  client.sendHeader("Authorization", authHeader);
  client.endRequest();

  int status = client.responseStatusCode();

  if(status == 201) {
    Serial.println("Data has been saved");
  } else {
    Serial.write("Error ");
    Serial.println(status);
  }

  client.stop();
  delay(5000);

}

Request to authentication enpoint works well, returning the access token. But the second request always return -3 status. If i make only one request to a random url it works, but the second fails. The second request never appears in my API logs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: imperfectionPerceived defect in any part of projectPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.