0

Here is the code that I have used for Async Http requests using loopj.

AsyncHttpClient loopjClient = new AsyncHttpClient();

    PersistentCookieStore loopjCookieStore = new PersistentCookieStore(this);
    loopjClient.setCookieStore(loopjCookieStore);

    RequestParams loopjParams = new RequestParams();
    loopjParams.put("username", username);
    loopjParams.put("email", emailID);
    loopjParams.put("password", password);
    Log.d(TAG, "RRRRRRlll");

    loopjClient.post("http://www.example.com/", loopjParams, new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int k,String response) {
            super.onSuccess(k, response);
            Log.d(TAG, "RRRRRR "+ response );
        }


    });

And my server response string is just the following with out the HTML tags

{"AUTHENTICATION":{"SUCCESS":false,"USERNAME":"unregistered","USERID":0},"ALERTBOX":{"SHOW":true,"MESSAGE":"Message : Username or email ID already registered. Please choose a different one."}}

But loopj doesnt print the above string in onSuccess().

Can you tell how to get the string or do I have to fall back to default Android http library ?

Thanks in advance.

EDIT

Instead of 'example'(my site) if I replace it with 'facebook' I just get the following string as response with a 200 response code <?xml version="1.0" encoding="utf-8"?>

rahulg
  • 2,183
  • 3
  • 33
  • 47

1 Answers1

1

Since the result of AUTHENTICATION failed, I'm wondering if the status code that your server return is not 200. You can override onFailure method to deal with this situation.

@Override
public void onFailure(Throwable e) {
    Log.d(TAG, e.toString());
}


Edit
Another guess, have you added the following line in your Manifest.xml?

<uses-permission android:name="android.permission.INTERNET" />


Edit Again
I saw your edit, and it seems that you have an buggy LogCat as @shailendra-rajawat mentioned in comment, since LogCat printed only the first line. Try Toast instead:

@Override
public void onSuccess(int k, String response) {
    Toast.makeText(getBaseContext(), response, 1).show();
}

I found this post for configuring your LogCat, and maybe you can give it a try. (Mine is 5000 FYI)

Community
  • 1
  • 1
iForests
  • 6,757
  • 10
  • 42
  • 75
  • First of all, this is not HTTP authentication, so failure shown in the string is not related to HTTP authentication. Secondly, the response code that I am getting is 200 but not getting any text along with it. :( – rahulg Mar 21 '13 at 08:57
  • @rahulg So what is the error message in onFailure()? The HttpResponseHandler will go into either onSuccess or onFailure, but not both. Can you post the url here? – iForests Mar 21 '13 at 09:07
  • Sure, I am trying to register to http://www.pikspeak.com/register.php by sending post data. – rahulg Mar 21 '13 at 09:09
  • Is it that loopj just returns the contents inside the `

    ` tags

    – rahulg Mar 21 '13 at 09:20
  • @rahulg I've tested the Url with your code, and it worked well. Check your manifest for permission of internet (see my answer above, I've edited it). – iForests Mar 21 '13 at 09:40
  • thanks a lot but I have already given that permission. Can you please tell what verion of `loopj` (`android-async-http`) are you using. I hope its some issue with the latest version. – rahulg Mar 21 '13 at 09:45
  • 1
    @rahulg The latest one. I downloaded it 10 mins ago. The first line of the response is an empty line, try to remove it and test again. Maybe your LogCat is unable to print out messages that contains new line character for some reasons. – iForests Mar 21 '13 at 09:48
  • Yup, some issue with logcat cause I can see the expected value in Toast. Weird, I have never had this issue with logcat before. Do you know why this happens? Write down this answer, I ll accept this answer. Thnx a ton. – rahulg Mar 21 '13 at 10:49
  • @rahulg I've edited my answer, and there is a link which may be helpful. Good luck. – iForests Mar 21 '13 at 10:59