Java HTTP Read readError(HttpURLConnection conn)

Here you can find the source of readError(HttpURLConnection conn)

Description

_more_

License

Apache License

Parameter

Parameter Description
conn _more_

Return

_more_

Declaration

public static String readError(HttpURLConnection conn) 

Method Source Code

//package com.java2s;
/*/*ww  w. j  a v a  2 s  .  c  o m*/
* Copyright (c) 2008-2018 Geode Systems LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
*     http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import java.io.*;
import java.io.*;

import java.net.*;

public class Main {
    /**
     * _more_
     *
     * @param conn _more_
     *
     * @return _more_
     */
    public static String readError(HttpURLConnection conn) {
        try {
            return readString(new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8")));

        } catch (Exception exc) {
            return "No error message";
        }
    }

    /**
     * _more_
     *
     * @param input _more_
     *
     * @return _more_
     *
     * @throws Exception _more_
     */
    public static String readString(BufferedReader input) throws Exception {
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = input.readLine()) != null) {
            sb.append(line);
            sb.append("\n");
        }

        return sb.toString();
    }

    /**
     * _more_
     *
     * @param sb _more_
     * @param s _more_
     *
     * @return _more_
     */
    public static Appendable append(Appendable sb, String s) {
        try {
            sb.append(s);

            return sb;
        } catch (java.io.IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }

    /**
     * _more_
     *
     * @param o _more_
     *
     * @return _more_
     */
    public static String toString(Object o) {
        if (o == null) {
            return "";
        }

        return o.toString();
    }
}

Related

  1. getJsonFromUrlWithJsonParameter(String url, String jsonRequest)
  2. getJsonString(String url)
  3. getReader(String url)
  4. getResult(String urlStr, String content)
  5. readData(HttpURLConnection conn)
  6. readGetEx(String url)
  7. readHTTPConnection(HttpURLConnection conn)
  8. readHttpConnection(HttpURLConnection h)
  9. readHttpFile(String fileUrl, String referer)