I have created my server in amazon ec2 instance. Through my android app i am connecting to the server with HttpUrlConnection. But i get response code as -1. Does anyone has any idea ?? Here is my code. private String getHttpResponse(final String srcUrl) {
    HttpURLConnection urlConnection = null;
    FileOutputStream fos = null;
    try {
        URL url = new URL(srcUrl);
        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.setRequestProperty("Content-Type", "application/json");
        mETag = readETagFromPrefForCategory();
        urlConnection.setRequestProperty("If-None-Match", mETag);
        Authenticator.setDefault(new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("xyz", "abc".toCharArray());
            }
        });
        urlConnection.connect();
        mETag =  urlConnection.getHeaderField("ETag");
        if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
            Log.v("http","not modifed");
            return readLocalJson();
        }
        if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
            Log.w(TAG, "Bad response [" + urlConnection.getResponseCode() + "] from (" + srcUrl + ")");
            return null;
        }}//end of try block