【问题标题】:I'm not getting the response from a webpage我没有收到来自网页的响应
【发布时间】:2013-01-05 15:36:43
【问题描述】:

我是 Java/Android 的新手,我有一个代码来获取网页的响应。我有这样的代码,但由于某种原因,BufferedReaderin.readLine() 总是返回 null。

URL url = new URL(endPoint);
connection = (HttpURLConnection) url.openConnection();

connection.setConnectTimeout(connectionTimeout);
connection.setReadTimeout(readTimeout);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", "" + Integer.toString(encodedParams.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);

// Setup the POST payload
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(encodedParams);
wr.flush();
wr.close();

// Read the response
InputStream inputStream = connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));

不确定我在哪里犯了错误。

提前致谢。

【问题讨论】:

  • 你有代理设置吗???如果“是” url 连接不起作用..

标签: java android web bufferedreader


【解决方案1】:

试试

connection.connect();

在阅读回复之前

【讨论】:

  • 我没有否决您的回答。我添加了 connect() 方法,但我又没有得到任何响应。也没有抛出异常。
猜你喜欢
  • 2013-01-03
  • 2021-10-29
  • 1970-01-01
  • 2012-01-27
  • 1970-01-01
  • 2015-03-05
  • 1970-01-01
  • 2015-10-12
  • 1970-01-01
相关资源
最近更新 更多