通过代码示例跟我学commons-httpclient3组件技术及应用实例第2部分内容摘要:

必究 , 10/24 页 int StatusCode=()。 if (StatusCode == || StatusCode == || StatusCode == || StatusCode== ){ Header locationHeader = (location)。 String redirectURL = null。 if (locationHeader != null ) { redirectURL = ()。 //读取新的 URL 地址 (页面将要重定向到: +redirectURL)。 } } else{ (方法执行过程中出现了错 误 )。 //打印服务器返回的状态 } ()。 } public static void main(String[] args) throws HttpException,IOException{ WebBankUserLogin oneWebBankUserLogin=new WebBankUserLogin()。 } } 本实例的程序代码 执行的结果 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 杨教授工作室,版权所有,盗版必究 , 11/24 页 直接执行重定向目标页面的示例 package。 import。 import。 import。 import。 import。 import。 import。 import。 import。 import。 import。 public class WebBankUserLogin { public WebBankUserLogin() throws HttpException,IOException{ HttpClient client = new HttpClient()。 //如果需要设置 Cookie ().addCookie(arg0)。 String targetURL= PostMethod onePostMethod = new PostMethod(targetURL)。 //设置传输字符集,如果需要传输中文这需要设置为中文字符集 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 杨教授工作室,版权所有,盗版必究 , 12/24 页 (ContentType, application/xformurlencoded。 charset=gb2312)。 NameValuePair verifyCodeDigit = new NameValuePair(verifyCodeDigit,1234abcd)。 NameValuePair type_User_Admin = new NameValuePair(type_User_Admin,1)。 NameValuePair userName = new NameValuePair(userName,yang)。 NameValuePair userPassWord = new NameValuePair(,1234)。 (new NameValuePair[] {verifyCodeDigit, type_User_Admin,userName,userPassWord})。 (onePostMethod)。 int StatusCode=()。 if (StatusCode == || StatusCode == || StatusCode == || StatusCode== ){ Header locationHeader = (location)。 String redirectURL = null。 if (locationHeader != null ) { redirectURL = ()。 //读取新的 URL 地址 GetMethod redirectTarget = new GetMethod(redirectURL)。 (redirectTarget)。 InputStream oneInputStream = ()。 InputStreamReader oneInputStreamReader=new InputStreamReader(oneInputStream)。 BufferedReader oneBufferedReader=new 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 杨教授工作室,版权所有,盗版必究 , 13/24 页 BufferedReader(oneInputStreamReader)。 String oneLineString=null。 while((oneLineString=())!=null){ (oneLineString)。 //打印返回的结果行信息 } } } else{ (方法执行过程中出现了错误 )。 //打印服务器返回的状态 } ()。 } public static void main(String[] args) throws HttpException,IOException{ WebBankUserLogin oneWebBankUserLogin=new WebBankUserLogin()。 } } 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 杨教授工作室,版权所有,盗版必究 , 14/24 页 在 多线程模式下 如何应用 HttpCl。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。