httpurlconnection没有收到服务器的响应

时间:2016-01-27 06:00:33

标签: android httpurlconnection

在我的项目中,我使用 HttpURLConnection 来发布数据。 数据已成功发布,但我没有收到服务器响应。

这是我的代码:

try {
                // httpurlconnection post data
                PrintWriter out = new PrintWriter(conn.getOutputStream());
                out.print(urlParameters);
                out.close();

                //build the string to store the response text from the server
                String content = "";
                if (conn.getResponseCode() != 201) {
                    BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
                    ErrorClass error = new Gson().fromJson(br, ErrorClass.class);
                    // throw the error message to the application
                    throw new Exception(content);
                }
                return content;
            } catch (IOException ignored) {
            }

0 个答案:

没有答案