Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
geovannyAvelar opened this issue Jul 8, 2017 · 4 comments
Open

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

geovannyAvelar opened this issue Jul 8, 2017 · 4 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@geovannyAvelar
Copy link

geovannyAvelar commented Jul 8, 2017

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.

@melvinpmathew
Copy link

melvinpmathew commented Aug 9, 2017

I am also kind off in the same boat. SSL connection not working when using local SSL server, give me -3 error code. HTTPS failing 🙁

Turning off SSL-regular HTTP request works fine with basic auth and POST messaging.

Is this a known issue? Is there any support or other ways to achieve SSL?

@sandeepmistry
Copy link

@geovannyAvelar @melvinpmathew could you please share a full sketch to reproduce this and let us know what hardware you are using.

@Bl4cksunLtd
Copy link

Bl4cksunLtd commented Mar 31, 2018

I've had the same issue. Firstly I connect to /endpoint1 (and download some data) then later connect to /endpoint2 (to upload data). The server accepts the data sent to /endpoint2 (it's a json message) and continues without issue, however the client fails at that point with a timeout error (-3). Repeatedly calling the /endpoint2 send routine (after a delay(5000), will fail every time with a -3.
I've found a work around for me that might be useful to others and maybe highlight the potential cause of the problem. Instead of using a single wificlient and httpclient for requests to both endpoints, I added a second wificlient and httpclient that use the same server address and port, but the second set of clients are used with /endpoint2. I can repeatedly make calls to the second endpoint after grabbing data from the first endpoint (with the original set of clients). So it seems like the problem is caused by changing endpoints between calls.
Scratch all the above. It did appear to get round the problem, but I started getting the timeout (-3) errors on the 4th or 5th call to /endpoint2.

@Warlib1975
Copy link

I've got the same -3 error instead of 403 error when using SSL connection. When I try to connect to the server using c# application it shows standard 403 auth error. It's ok. -3 code is informative.

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

6 participants