Question

I have been trying to get the Kinvey handshake for the REST api to work for a while now but have not had any luck. I am using libgdx's net class to send the http request. Wverytime I send the request I get a 504(Gateway Timeout) error. I am following the instructions on the website so I am not sure why I would get that error.

Here is my attempt:

    HttpRequest request = new HttpRequest(HttpMethods.GET);
    request.setHeader("GET", "/appdata/:App_key");
    request.setHeader("Host:", "baas.kinvey.com");
    String authHeader = "Basic " + Base64Coder.encodeString("App_key:App_secret");
    request.setHeader("Authorization:", authHeader);
    request.setUrl("https://baas.kinvey.com/appdata/App_key");
    System.out.println("HTTP REQUEST: " + request.getHeaders());
    responseListener listener = new responseListener() {
        public void handleHttpResponse (HttpResponse httpResponse) {

                HttpStatus status = httpResponse.getStatus();

                if (status.getStatusCode() >= 200 && status.getStatusCode() < 300) {
                    System.out.println("HTTP SUCCESS!");
                } else {
                    System.out.println("HTTP ERROR: " + status.getStatusCode());
                }
                System.out.println("HTTP :" + httpResponse.getResultAsString());
        }

        @Override
        public void failed(Throwable t) {
            t.printStackTrace();
            System.out.println("REQUEST FAILED!" +t.getMessage());
            super.failed(t);
        }

    };

    Gdx.net.sendHttpRequest(request, listener);

As far as I can tell, there is something wrong with the header. I have tested the Url which takes me to a login screen. The login works after I put in the App key as the user name and the Master secret as the password. Is there something obviously wrong? Is there a way I can debug this further?

Was it helpful?

Solution

I'm an engineer at Kinvey and can help you out with this.

A couple things:

first, there are some extra headers there that you don't need. While they might not be the cause of the issue, it is still safe to remove:

request.setHeader("GET", "/appdata/:App_key");
request.setHeader("Host:", "baas.kinvey.com");

Note that GET is set when you create the HttpRequest, and Host is set when you define the URL.

Second, get rid of the colon after "authorization" when setting your header, make it look like this:

request.setHeader("Authorization", authHeader);

Also, you mention that it works with your master secret but not with your app secret? Can you ensure that you are base64 encoding both?

One last thing-- ensure that you replace App_Key with your actual app key, in the URL as well as in the headers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top