简体   繁体   中英

Issues with REST-API in parse after migrating to Parse-Server

I am trying to migrate the Parse-server to a Debian Server and I am running into some trouble with the REST-API. When I try to call my application's login-function I receive the following error: Cannot POST /parse/login .

These are the steps I have followed successfully before I received a server error.

  1. Installed Parse-Server in Debian
  2. Installed the cloud code and added my code to the file main.js .
  3. My cloud code contains a login-function and I had a successful call with curl -H "X-Parse-Application-Id: <id1>" -H "Content-Type: application/json" -d '{}' 'serverName/parse/functions/login' .
  4. The final step was to call the REST-API which gave me a Cannot POST /parse/login error. I called it with curl -H "X-Parse-Application-Id: <id1>" -H "Content-Type: application/json" -d '{}' 'serverName/parse/login'

This is the migration guide I have followed This is the REST-API guide I have followed.

Can someone help me with this server error?

Correct. Login requires the GET method not POST !

By doing a simple GET to that URL , you should then be presented with the below error. Obviously you need to pass your params to make it successful.

 {
        "code": 200,
        "error": "username is required."
    }

Removing the -d '{}' will revert that curl to a GET

This answer is the best shot I can do with the information provided. The problem is most likely that the application is expecting a GET request (or some other HTTP method other than POST ) but your curl request sends a POST request.

To see what curl is sending you can add -v (I put in example.com just to have a server which responds)

$ curl -v -H "X-Parse-Application-Id: <id1>" -H "Content-Type: application/json" -d '{}' 'example.com/serverName/parse/login'
*   Trying 2606:2800:220:1:248:1893:25c8:1946...
* TCP_NODELAY set
* Connected to example.com (2606:2800:220:1:248:1893:25c8:1946) port 80 (#0)
> POST /serverName/parse/login HTTP/1.1
> Host: example.com
> User-Agent: curl/7.51.0
> Accept: */*
> X-Parse-Application-Id: <id1>
> Content-Type: application/json
> Content-Length: 2

The login function in the API guide expects a GET request:

To do this, send a GET request to the /1/login endpoint with username and password as URL-encoded parameters:

I assume with the migration you also upgrade to a newer parse.com app and the older version accepted POST and the newer one not.

You'll need to change your curl request to use GET instead of POST . Just follow the example provided . Remove the -d parameter and add the --data-urlencode parameters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM