3
connection = (HttpURLConnection)new URL(mURL).openConnection();
connection.setRequestMethod("GET");
String basicAuth = params[0] + ":" + params[1];
basicAuth = "Basic " + new String(Base64.encode(basicAuth.getBytes(),Base64.NO_WRAP));
connection.setRequestProperty("Authorization",basicAuth);
connection.connect();
InputStream in = connection.getInputStream();

I have gone through all possible questions based on this on SO but with out any success. I am trying to connect to my server using basic authentication. But when I try to access the input stream from URLConnection it throws IOException. Thanks for any help from any one of you.

CodeDecode
  • 401
  • 2
  • 10
  • 19
  • 1
    Do you have the internet permission declared in your manifest? – dymmeh Oct 28 '13 at 21:01
  • Those every thing is set I do have other HTTP request happening parallel in my application – CodeDecode Oct 28 '13 at 21:11
  • Throws *what* `IOException.` With what message? stack trace? – user207421 Oct 29 '13 at 02:07
  • File not found exception. And Thanks for all of your time I was bit late to respond. I fixed the issue connection.setRequestProperty("Authorization",basicAuth); instead of this I added connection.addRequestProperty("Authorization",basicAuth); now it working fine now. But I do like to know what effect this will make over the request. – CodeDecode Oct 29 '13 at 08:43

1 Answers1

1

Basically, here there could be a few things that can go wrong. Does the URL you are trying to connect to exist? If not, may be you may have to redirect. Also, try

connection.getResponseCode();

and make sure it returns 200 or HTTP_OK

Needs more information to say anything. Go to debug mode and try to get the states of different objects used here.

Similar to IOException: "Received authentication challenge is null" (Apache Harmony/Android)

Community
  • 1
  • 1
BudsNanKis
  • 224
  • 5
  • 17