HTTPCLIENT POST GET请求模拟
来源:互联网 发布:淘宝店铺如何上货 编辑:程序博客网 时间:2024/05/14 01:29
一、POST请求:
private static void post(String url) {PostMethod postMethod = null;GetMethod getMethod = null;String captchaCode = "0251";String sessionId = "r0fud17p49zenksx97uzdre7";try {HttpClient client = new HttpClient();postMethod = new PostMethod(url);NameValuePair[] arr = new NameValuePair[3];NameValuePair username = new NameValuePair("username","ppt");arr[0] = username;NameValuePair password = new NameValuePair("password","ppt");arr[1] = password;NameValuePair captcha = new NameValuePair("captcha",captchaCode);arr[2] = captcha;postMethod.setRequestHeader("Cookie", "JSESSIONID="+sessionId);postMethod.setRequestBody(arr);int status = client.executeMethod(postMethod);if(status == HttpStatus.SC_MOVED_TEMPORARILY) {Header[] header = postMethod.getResponseHeaders();for(Header hh : header) {String headerName = hh.getName();if("Location".equals(headerName)) {String value = hh.getValue();getMethod = new GetMethod(value);getMethod.setRequestHeader("Cookie", "JSESSIONID="+sessionId);int statu = client.executeMethod(getMethod);if(statu == HttpStatus.SC_OK) {String str = getMethod.getResponseBodyAsString();System.out.println(str);}}}}if(status == HttpStatus.SC_OK) {String content = postMethod.getResponseBodyAsString();System.out.println(content);} else {System.out.println("http status: " + status);}} catch(Exception e) {e.printStackTrace();} finally {if(postMethod != null) {postMethod.releaseConnection();}if(getMethod != null) {getMethod.releaseConnection();}}}
二、GET 请求:
private static void get(String url) {GetMethod method = null;try {HttpClient client = new HttpClient();method = new GetMethod(url);method.setRequestHeader("Cookie", "JSESSIONID=2D94ED969F39054DDB4444CFE24F550F");int status = client.executeMethod(method);if(status == HttpStatus.SC_OK) {String content = method.getResponseBodyAsString();System.out.println(content);} else {System.out.println("http status:" + status);}} catch(Exception e) {e.printStackTrace();} finally {method.releaseConnection();}}
0 0
- HTTPCLIENT POST GET请求模拟
- java使用httpclient模拟post请求和get请求示例
- Android--httpclient模拟post请求和get请求
- httpClient post/get请求。
- HttpClient get,Post请求
- HttpClient get、post请求
- HttpClient模拟Post请求
- HttpClient模拟HTTP的GET和POST请求
- UWP——HttpClient模拟浏览器的GET、POST请求
- java使用HttpClient模拟发送http的get、post请求
- httpClient----Post 和 GET请求
- HTTPClient get post 请求方式
- HttpClient Post、get 请求方式
- HttpClient请求服务器 get post
- HttpClient发起GET / POST请求
- HttpClient发起post、get请求
- HttpClient (POST GET PUT)请求
- HttpClient Post、get 请求方式
- android apk安装方式
- Binary Tree Preorder Traversal
- 复制打包文件内的文件到指定文件内
- Android平台输入法开发解析
- Multiple dex files define Lorg/apache/commons/codec/Decoder; 我的解决方案
- HTTPCLIENT POST GET请求模拟
- IOS小知识点12之IOS查看网页、发短信、打电话、发邮件
- android技术类总结
- 独立开发者:新手做2D手游该用哪些工具
- Androd学习笔记——OAuth 认证步骤
- iOS操作系统的层次结构
- 虚拟软键盘与输入法
- Ansible vs Chef
- MySQL中concat函数(连接字符串)