开发者

How do I get my Android application login to a server?

I want to ask about the best way to let an Android application log in to a server (PHP). Do I have to use a session? I want to log in and send some information to the server and save that information in the database.

I currently use this:

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(path);

And then use JSON开发者_运维百科 to send the data. I want a good way to verify the Android app identity to my server page.


Not difficult. You don't really 'log in' per se with HTTP (the web's protocol), you open a one-time connection to perform your task. On Android you'll be looking at something like this:

        try {
            URL url = new URL("http://yourserver.com/yourpage.php");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestMethod("PUT");
            OutputStreamWriter output = new OutputStreamWriter(connection.getOutputStream());
            output.write(  // ... );
            output.close();
        } catch (IOException e) {
        // Handle error
    }


You're going to have to build an API.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜