利用httpclient模拟站点的登录发帖回复 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-21
{ 104 method.setRequestHeader( " Accept " , " */* " ); 105 // method.setRequestHeader("Accept-Language", "zh-cn"); 106 // method.setRequestHeader("Accept-Encoding", "gzip,deflate"); 107 method.setRequestHeader( " User-Agent " , " Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;) " ); 108 // 譜崔掲械嶷勣 109 method.setRequestHeader( " Connection " , " Keep-Alive " ); 110 } 111 112 public String redirectToURL(String url) throws IOException 113 { 114 if (url != null ) { 115 try { 116 System.out.println( " 匈中嶷協?欺? " + url); 117 String responseString = this .doCommonVisitWithURL(url); 118 // System.out.println(responseString); 119 return responseString; 120 } catch (IOException e) { 121 System.out.println( " 嶷協?? " + url + " 竃危 " ); 122 } 123 } else { 124 System.out.println( " redirect url is null " ); 125 } 126 return null ; 127 } 128 129 public String doCommonVisitWithURL(String url) throws IOException { 130 GetMethod get = new GetMethod(url); 131 return this .doGet(get); 132 } 133 134 public String doPost(ExpectContinueMethod post) throws IOException 135 { 136 if (post == null ) 137 return null ; 138 try 139 { 140 if (getCookies() != null ) { 141 // printCookies(); 142 client.getState().addCookies(cookies); 143 post.addRequestHeader( " Cookie " ,getCookies().toString()); 144 // System.out.println(post.getRequestHeader("Cookie").getValue()); 145 } 146 setCommonMethodRequestHeaders(post); 147 int statusCode = client.executeMethod(post); 148 cookies = client.getState().getCookies(); 149 System.out.println(statusCode); 150 // System.out.println(post.getResponseHeader("Location")); 151 String responseString = post.getResponseBodyAsString(); 152 System.out.println(responseS |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于利用httpclient模拟站点的登录发帖回复 - 编程入门网的所有评论