douxiyi2418 2016-05-01 10:47
浏览 37
已采纳

我需要拒绝从Cordova先前的应用程序版本登录到我的服务器

I have made an app in javascript using Apache Cordova, and now i´m gonna use a new one written in java.

my app communicates with a php webservice, so, what are my options to deny the previous app to login ?

  1. I think one option may be versioning the new one and consulting it for every time that a login its requested.

but at the moment, I don't know ..

note: the previous app is distributed via email to the workers so I can't just update from a server and replace it.

  • 写回答

2条回答 默认 最新

  • duanran3115 2016-05-01 10:55
    关注

    You could have your Java client add a header when talking to your webservice, possibly a specific user agent. Or have it send a accept header which includes a version:

    GET /jobs HTTP/1.1
    Host: api.example.com
    Accept: application/vnd.example.api+json;version=2
    

    Your webservice can check the presence of the Accept header and the version string in it and decide what to do based on that.

    You could return a value that is compatible with the old client and a different value that is compatible with the new client. or you can simply return a 404 or a 501 status code with an error message to the old client.

    The generic process is explained here in detail:

    Applying this to PHP and Java is relatively simple:

    As an alternative you can add a version value to your request using a post variable, querystring parameter or as part of the request body (in JSON). I personally like it less than the use of accept headers, since the last is more flexible in the long run. You can even add multiple values to an accept header to indicate which versions you support. Your server can reply with the version it responded with. Giving you a better long-term solution.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?