0

I am accessing a REST web service via Mozilla client via Mozilla browser. (In web service

back end spring security has configured and credentials for each

request is validated). So I am setting basic authentication (username and password) and

Request header "application/json" which is fine.

Now I want to connect to this web service via a android application as below. How do I set

credentials of the user (username and password) to the request ?

       @Override
        protected Void doInBackground(Void... params) {

            HttpClient client = new DefaultHttpClient();
            WsUrl="http://192.168.0.15:8080/ServiceApp/categoryservice/category/001"; // RESTFUL URL RESOURCE
            HttpGet getRequest = new HttpGet(WsUrl);

            try {

                HttpResponse response=client.execute(getRequest);
                StatusLine statusLine = response.getStatusLine();
                int statusCode = statusLine.getStatusCode();

                if(statusCode != 200){
                    return null;
                }


        InputStream jsonStream = response.getEntity().getContent();
        ufferedReader reader = new BufferedReader(new InputStreamReader(jsonStream));
Tanmay Mandal
  • 39,873
  • 12
  • 51
  • 48
Kasun
  • 561
  • 11
  • 22

1 Answers1

0

check the link for answer, I don't what kind of authentication you are using, but this link shows how to windows basic authentications

HTTP requests with basic authentication

Community
  • 1
  • 1
Syed Waqas
  • 862
  • 2
  • 9
  • 29