最后在通过HttpURLConnection获取网页内容时发现一个小bug.发出请求时一直返回400  Bad Request,获取流数据时返回-1,后面查找发现是服务端进行跳转了。

  解决办法很简单,设置setInstanceFollowRedirects为false就行,注明不进行跳转,也可以通过getHeaderField("Location")获取到要跳转的URL。

       看看SDK的说明,编码之后熟读一下相关的API还是好处多,不然绕了半天才找到方法。

public void setInstanceFollowRedirects (boolean followRedirects)

Since: API Level 1

Sets whether this connection follows redirects.

Parameters
followRedirects

true if this connection will follows redirects, false otherwise.