Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
Parse.Cloud.httpRequest returns 'undefined' instead of a response using POST method

I'm making a Parse.Cloud.httpRequest using the POST method to retrieve a token from an API in a Back4App Cloud Code Function called 'retrieveToken'.

Parse.Cloud.define("retrieveToken", async(request) => {
  Parse.Cloud.httpRequest({
    method: 'POST',
    url: 'https://.......',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body: {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "...",
              "password": "...",
              "domain": {
                "name": "..."
              }
            }
          }
        },
        "scope": {
          "project": {
            "id": "..."
          }
        }
      }
    }
  }).then(function(httpResponse) {
    console.log('Token retrieved successfully, Status Code: ', httpResponse.status, ',\n', httpResponse.text);
  }, function(httpResponse) {
    console.error('Failed to retrieve token, retrieveToken: ', httpResponse.status, ',\n', httpResponse.text);
  });
});

It works fine if I delete "project": {"id": "..."} from the 'scope' of the body JSON of the httpRequest.

However, it returns me 'undefined' if I don't delete that chunk of code.

I have to keep that chunk of code there because the API will return me a project-level token only if I specify the project id. Otherwise, I will get a global-level token, which cannot be used for my case.

The API works perfectly with/without the project id specified in Postman.

I have already stuck here for a whole day and still can't figure it out. Where am I doing wrong and how can I get the correct response from Parse.Cloud.httpRequest with the project id specified?

Update:

I found the content-length for the responses are quite different with/without the project id specified using Postman.

'content-length' = 6752 Bytes without the project id specified

'content-length' = 16896 Bytes with the project id specified

By any chance the 'undefined' was caused by the response size limit? If this is the reason, how can I get the correct response? Can I receive the header only?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Part of the problem happens because you are not returning the http response. Try this:

Parse.Cloud.define("retrieveToken", (request) => {
  return Parse.Cloud.httpRequest({
    method: 'POST',
    url: 'https://.......',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body: {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "...",
              "password": "...",
              "domain": {
                "name": "..."
              }
            }
          }
        },
        "scope": {
          "project": {
            "id": "..."
          }
        }
      }
    }
  }).then(function(httpResponse) {
    console.log('Token retrieved successfully, Status Code: ', httpResponse.status, ',\n', httpResponse.text);
    return httpResponse;
  }, function(httpResponse) {
    console.error('Failed to retrieve token, retrieveToken: ', httpResponse.status, ',\n', httpResponse.text);
    return httpResponse;
  });
});
about 4 years ago · Juan Pablo Isaza Relatório

0

This issue was resolved by adding an environment variable to my Back4App server.

NODE_OPTIONS="--max-http-header-size=16384"

I knew the exact problem (header overflow) by using the code below:

Parse.Cloud.define("retrieveToken", async(request) => {
  return Parse.Cloud.httpRequest({
    method: 'POST',
    url: 'https://.......',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body: {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "...",
              "password": "...",
              "domain": {
                "name": "..."
              }
            }
          }
        },
        "scope": {
          "project": {
            "id": "..."
          }
        }
      }
    }
  });
});

Only the code above returned me the error below, and all other code returned me 'undefined':

[Error]: Parse Error: Header overflow (Code: 141, Version: 1.19.2)

FYI: I'm calling this API

https://iam.ap-southeast-1.myhuaweicloud.com/v3/auth/tokens
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda