0

I am using JSON for parsing data in android. I have a JSON URL which requires username and password for authentication. I just went through the below tutorial for implementing JSON.

JSON implmentation

It is easy to implement but in my application i need to send the username and password for authentication. I am bit confused about this.

Can anyone please tell me how to set Content-Type, accept, Authorization in JSON.

Thanks.

2
  • Can you share the url? Commented Nov 5, 2013 at 15:15
  • Sorry. i cant share the URL. Commented Nov 5, 2013 at 15:22

2 Answers 2

1

What you need is to HTTP authentication, not JSON authentication. Refer this link to see how to make HTTP Connections in Android. This is the code snippet for you to authenticate using normal HTTP authentication.

 Authenticator.setDefault(new Authenticator() {
     protected PasswordAuthentication getPasswordAuthentication() {
       return new PasswordAuthentication(username, password.toCharArray());

   });
 }

This is example using HTTPClient.

This is another code snippet that deals with adding HTTP headers, the way you want.

Clarity of the question is in direct proportion with the accuracy and precision of the answer. Being little clearer will be better :)

Sign up to request clarification or add additional context in comments.

Comments

0

you can use this library: http://loopj.com/android-async-http/ i use it for Json and more and is simple to use

2 Comments

Is there any other way to set Authorization without using the library.
this user and pass i image is stored in a DB right?..you must create a post request, and response in Json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.