代码是这样的:
try{
String url= "http://m.qzone.qq.com/cgi-bin/new/msgb_output_page?uin=1234567&start=1&json=1&num=4";
URL login = new URL(url);
HttpURLConnection conn =null;
conn =(HttpURLConnection)login.openConnection();//openConnection();//打开链接
HttpURLConnection.setFollowRedirects(true);
// conn.setRequestProperty( "username ", "username ");
// conn.setRequestProperty( "password ", "userpwd ");
conn.setDoOutput(true);
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
conn.setRequestMethod( "GET"); //
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String text ="";
while( null != br.readLine()){
text = text +br.readLine();
System.out.println(br.readLine());
}
}catch(Exception e){}
用浏览器 返回的数据就是正常的、
try{
String url= "http://m.qzone.qq.com/cgi-bin/new/msgb_output_page?uin=1234567&start=1&json=1&num=4";
URL login = new URL(url);
HttpURLConnection conn =null;
conn =(HttpURLConnection)login.openConnection();//openConnection();//打开链接
HttpURLConnection.setFollowRedirects(true);
// conn.setRequestProperty( "username ", "username ");
// conn.setRequestProperty( "password ", "userpwd ");
conn.setDoOutput(true);
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");
conn.setRequestMethod( "GET"); //
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String text ="";
while( null != br.readLine()){
text = text +br.readLine();
System.out.println(br.readLine());
}
}catch(Exception e){}
用浏览器 返回的数据就是正常的、
解决方案 »
- java代码中执行数据库字段属性问题
- 大数据量查询后封装WebService的DTO方案
- 求精通j2ee--eclipse、struts、hibernate及spring整合应用案例 随书光盘
- 怎么给项目加一个补丁(急)
- 一台配置好JMS队列的JBoss 服务器,在另一台机器上通过Java程序连接并且发送、读取其上的队列的消息。
- 使用cxf开发webservice的时候,方法无法获得返回值???
- SpringAoP的BeanNameAutoProxyCreator自动拦截action时报action类型错误
- Hibernate有时查询不到最近插入的数据
- 请问如何用dom得到一个元素的内容?
- 跪求解决springmvc responsebody返回中文乱码
- hibernate注解的问题
- Hibernate 主键生成策略的选择
while( (text2= br.readLine())!=null){
text = text +text2;}
System.out.println(text);实际上text一般是用stringbuffer或 stringbuilder的