3

I use okhttp to access my webpage. On first access a session variable on the server is set to me logged in. Next, i want to access a different part of the site that only works if I'm logged in. In the browser this works, but with okhttp it doesn't.

Example:

digit/index.php?action=login&un=newun&pw=pw

If un and pw is right, Session variable on php script is set to logged in.

Next:

My app needs to do some things now that I'm logged in, so,

http://digit/index.php?action=getDates

This should return a list of dates available to the user if I am logged in.

On a web browser, this works. Meaning that the session remains between both pages, I log in and the second page that I need to be logged in for works.

Ultimately, my issue is this:

new DownloadImageTask().execute("http://digit/index.php?action=login&name=unpow&pw=unpow");

Returns logged in.

Next I go to this site:

new DownloadImageTask().execute("http://digit/index.php?action=registerDate&dateid=2");

Error: Not logged in.

Here's my DownloadImageTask

        private class DownloadImageTask extends AsyncTask<String, String, String> {

    /** The system calls this to perform work in a worker thread and
     * delivers it the parameters given to AsyncTask.execute() */
    private String result;

    protected String doInBackground(String... urls) {

            Request request = new Request.Builder()
                    .url(urls[0])
                    .build();
            try {
                Response response = client.newCall(request).execute();
                big = response.body().string();
                publishProgress(big);
            } catch (IOException e) {
            }
        return big;
    }

    protected void onProgressUpdate(String ok)
    {
    }
    /** The system calls this to perform work in the UI thread and delivers
     * the result from doInBackground() */
    protected void onPostExecute(String result) {
        big = result;
        UpdateUI();
    }
}
Jan Chrbolka
  • 4,184
  • 2
  • 29
  • 38
David Kachlon
  • 599
  • 2
  • 5
  • 17
  • Does this answer your question? [How to implement cookie handling on Android using OkHttp?](https://stackoverflow.com/questions/24263921/how-to-implement-cookie-handling-on-android-using-okhttp) – Top-Master May 11 '22 at 07:19

0 Answers0