从一个action地址获取信息
get方法
String url_str ="http://127.0.0.1:8400/lxyyProduct/getProductUserNeedUpdate.action?ts="+maxTs;
URL url = new URL(url_str);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
int result = connection.getResponseCode(); if (result == )//如果等于200算连接成功
{
InputStream in;
in = connection.getInputStream();
BufferedReader breader = new BufferedReader(new InputStreamReader(in , "UTF-8"));
String str=breader.readLine();
}
post方法
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL; public class HttpUrlUtil { /**
* 通过HttpURLConnection模拟post表单提交
*
* @param path
* @param params 例如"name=zhangsan&age=21"
* @return
* @throws Exception
*/
public static String sendPostRequestByForm(String path, String params) throws Exception{
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");// 提交模式
// conn.setConnectTimeout(10000);//连接超时 单位毫秒
// conn.setReadTimeout(2000);//读取超时 单位毫秒
conn.setDoOutput(true);// 是否输入参数
byte[] bypes = params.toString().getBytes();
conn.getOutputStream().write(bypes);// 输入参数
InputStream inStream=conn.getInputStream();
return readInputStream(inStream);
} /**
* 从输入流中读取数据
* @param inStream
* @return
* @throws Exception
*/
public static String readInputStream(InputStream inStream) throws Exception{
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[];
int len = ;
while( (len = inStream.read(buffer)) !=- ){
outStream.write(buffer, , len);
}
byte[] data = outStream.toByteArray();//网页的二进制数据
outStream.close();
inStream.close(); String res = new String(data,"UTF-8"); return res;
} public static void main(String[] args) throws UnsupportedEncodingException, Exception
{
String path="http://www.kd185.com/ems.php";
String params="id=1&df=323"; System.out.println(sendPostRequestByForm(path,params));
}
}
从一个action地址获取信息的更多相关文章
- 使用UrlConnection请求一个url地址获取内容
访问网络需要加Internet权限:android.permission.INTERNET 使用UrlConnection请求一个url地址获取内容: //1.创建一个Url对 ...
- 根据URL地址获取对应的HTML,根据对应的URL下载图片
核心代码(获取HTML): #region 根据URL地址获取信息GET public static String GetResult(string url) { return GetResult(u ...
- C# HttpWebRequest 绝技 根据URL地址获取网页信息
如果要使用中间的方法的话,可以访问我的帮助类完全免费开源:C# HttpHelper,帮助类,真正的Httprequest请求时无视编码,无视证书,无视Cookie,网页抓取 1.第一招,根据URL地 ...
- 淘宝(新浪)API获取IP地址位置信息
package com.parse; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IO ...
- golang中内存地址计算-根据内存地址获取下一个内存地址对应的值
package main import ( "fmt" "unsafe" ) func main() { // 根据内存地址获取下一个字节内存地址对应的值 da ...
- 根据第三方提供的webservice地址获取文件信息
import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.en ...
- 9.Struts2在Action中获取request-session-application对象
为避免与Servlet API耦合在一起,方便Action类做单元测试. Struts2对HttpServletRequest.HttpSession.ServletContext进行了封装,构造了三 ...
- ph模拟登录获取信息
cURL 是一个功能强大的PHP库,使用PHP的cURL库可以简单和有效地抓取网页并采集内容,设置cookie完成模拟登录网页,curl提供了丰富的函数,开发者可以从PHP手册中获取更多关于cURL信 ...
- 【逆向篇】分析一段简单的ShellCode——从TEB到函数地址获取
其实分在逆向篇不太合适,因为并没有逆向什么程序. 在http://www.exploit-db.com/exploits/28996/上看到这么一段最简单的ShellCode,其中的技术也是比较常见的 ...
随机推荐
- 台大《机器学习基石》课程感受和总结---Part 1(转)
期末终于过去了,看看别人的总结:http://blog.sina.com.cn/s/blog_641289eb0101dynu.html 接触机器学习也有几年了,不过仍然只是个菜鸟,当初接触的时候英文 ...
- MySQL5.5 RPM安装的默认安装路径
MySQL5.5 RPM安装的默认安装路径 2011-06-20 10:34:32| 分类: MySQL|举报|字号 订阅 下载LOFTER客户端 由于一客户要求安装mysql- 5.5 ...
- Android自定义Dialog
Android开发过程中,常常会遇到一些需求场景——在界面上弹出一个弹框,对用户进行提醒并让用户进行某些选择性的操作, 如退出登录时的弹窗,让用户选择“退出”还是“取消”等操作. Android系统提 ...
- 利用zabbix监控某个目录大小
近期,因为JMS的消息堆积导致ApacheMQ频率故障(消息没有被消费掉,导致其数据库达到1.2G,JMS此时直接挂掉),很是郁闷!刚好自 己在研究zabbix.既然zabbix如此强大,那么它可以监 ...
- php __set() __get() __isset() __unset()四个方法的应用
一般来说,总是把类的属性定义为private,这更符合现实的逻辑.但是,对属性的读取 和赋值操作是非常频繁的,因此在PHP5 中,预定义了两个函数“__get()”和“__set()”来获 取和赋值其 ...
- Resumable Media Uploads in the Google Data Protocol
Eric Bidelman, Google Apps APIs team February 2010 Introduction The Resumable Protocol Initiating a ...
- 【OpenStack】OpenStack系列5之Cinder详解
源码下载安装 git clone -b stable/icehouse https://github.com/openstack/cinder.git pip install -r requireme ...
- Java for LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Linux的文件管理
绝对路径和相对路径: 绝对路径: /home/tony/Desktop 相对路径:Desktop 或者./Desktop不可写成/Desktop(这是绝对路径的写法) 其中.代表本层目录,..代表上层 ...
- Java for LeetCode 069 Sqrt(x)
Implement int sqrt(int x). Compute and return the square root of x. 解题思路一: public int mySqrt(int x) ...