从一个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,其中的技术也是比较常见的 ...
 
随机推荐
- 影像工作站的数据库安装错误之Win7系统下pg服务无法启动
			
1.关闭批处理 2.修改 PG安装路径下的Data文件下的pg_hba.conf文件中去掉IPv6的井号,如下图 3.结束pg进程 4.重启PG服务.
 - twisted udp编程
			
概述 Unlike TCP, UDP has no notion of connections. A UDP socket can receive datagrams from any server ...
 - yum缓存配置
			
引自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/09/2203916.html $ cat /etc/yum.conf ...
 - 特殊表达式的意义[c++ special expressions]
			
[本文链接] http://www.cnblogs.com/hellogiser/p/special-expressions.html x&(x-1)表达式的意义: 统计二进制中1的个数. ...
 - Android 中获得notification的发出时间
			
最近做程序时,有一个类似闹钟的功能,用notification唤醒程序后,希望能得到发出这个notification时的具体时间,就是notification右边写着的那个时间.查了notificat ...
 - codeigniter load_class
			
2014年7月7日 14:33:36 函数定义在 system/core/common.php中 使用方法是 load_class('Hooks', 'core'): 在core目录内寻找Hooks类 ...
 - BestCoder17 1002.Select(hdu 5101) 解题报告
			
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...
 - [编解码]   关于base64编码的原理及实现
			
转载自: http://www.cnblogs.com/hongru/archive/2012/01/14/2321397.html [Base64]-base64的编码都是按字符串长度,以每3个8b ...
 - ASP.Net和新对象之context.Server
			
描述 Server是一个HttpServerUtility类型的对象,不是一个类名 1.获取服务器上的绝对路径文件名tring ss = context.Server.MapPath("~/ ...
 - CocoaPods报错及解决方法记录
			
[!] Oh no, an error occurred. Search for existing GitHub issues similar to yours: https://github.com ...