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地址获取信息的更多相关文章

  1. 使用UrlConnection请求一个url地址获取内容

    访问网络需要加Internet权限:android.permission.INTERNET 使用UrlConnection请求一个url地址获取内容:             //1.创建一个Url对 ...

  2. 根据URL地址获取对应的HTML,根据对应的URL下载图片

    核心代码(获取HTML): #region 根据URL地址获取信息GET public static String GetResult(string url) { return GetResult(u ...

  3. C# HttpWebRequest 绝技 根据URL地址获取网页信息

    如果要使用中间的方法的话,可以访问我的帮助类完全免费开源:C# HttpHelper,帮助类,真正的Httprequest请求时无视编码,无视证书,无视Cookie,网页抓取 1.第一招,根据URL地 ...

  4. 淘宝(新浪)API获取IP地址位置信息

    package com.parse; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IO ...

  5. golang中内存地址计算-根据内存地址获取下一个内存地址对应的值

    package main import ( "fmt" "unsafe" ) func main() { // 根据内存地址获取下一个字节内存地址对应的值 da ...

  6. 根据第三方提供的webservice地址获取文件信息

    import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.en ...

  7. 9.Struts2在Action中获取request-session-application对象

    为避免与Servlet API耦合在一起,方便Action类做单元测试. Struts2对HttpServletRequest.HttpSession.ServletContext进行了封装,构造了三 ...

  8. ph模拟登录获取信息

    cURL 是一个功能强大的PHP库,使用PHP的cURL库可以简单和有效地抓取网页并采集内容,设置cookie完成模拟登录网页,curl提供了丰富的函数,开发者可以从PHP手册中获取更多关于cURL信 ...

  9. 【逆向篇】分析一段简单的ShellCode——从TEB到函数地址获取

    其实分在逆向篇不太合适,因为并没有逆向什么程序. 在http://www.exploit-db.com/exploits/28996/上看到这么一段最简单的ShellCode,其中的技术也是比较常见的 ...

随机推荐

  1. Nmap备忘单:从探索到漏洞利用 Part1

    在侦查过程中,信息收集的初始阶段是扫描. 侦查是什么? 侦查是尽可能多的收集目标网络的信息.从黑客的角度来看,信息收集对攻击非常有帮助,一般来说可以收集到以下信息: 电子邮件.端口号.操作系统.运行的 ...

  2. js中document.documentElement 和document.body 以及其属性 clientWidth等

    在设计页面时可能经常会用到固定层的位置,这就需要获取一些html对象的坐标以更灵活的设置目标层的坐标,这里可能就会用到document .body.scrollTop等属性,但是此属性在xhtml标准 ...

  3. Python操作Mysql实例代码教程在线版(查询手册)

    本文介绍了Python操作MYSQL.执行SQL语句.获取结果集.遍历结果集.取得某个字段.获取表字段名.将图片插入数据库.执行事务等各种代码实例和详细介绍,代码居多,是一桌丰盛唯美的代码大餐   实 ...

  4. Linux shell脚本编程基础之练习篇

    shell脚本编程基础之练习篇. 1.编写一个脚本使我们在写一个脚本时自动生成”#!/bin/bash”这一行和注释信息. #!/bin/bash ] then echo "请输入一个参数& ...

  5. 转mysql存储引擎memory,ndb,innodb之选择

    1 mysql的innodb和cluster的NDB引擎都支持事务,在有共同的特性外,也有不同之处:以mysql cluster NDB 7.3和MySQL 5.6之InnoDB为例:ndb7.3基于 ...

  6. mysql5.6 timestamp

    1.timestamp 默认值 CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 在创建新记录和修改现有记录的时候都对这个数据列刷新 CURRENT_TIME ...

  7. Java for LeetCode 151 Reverse Words in a String

    Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...

  8. 【python】lamda表达式,map

    一个很好的博客:http://blog.csdn.net/mathboylinlin/article/details/9413551 博客不让转载,我只摘抄了里面几个例子,更多内容到博客里去看 lam ...

  9. 解决iphone5,5s有锁版(AU,SB,S版等等)ios7越狱后+86、FT、IM等一切问题

    最近无聊,给大家发一个关于完美解决iphone5,5c.5s有锁版本机号码.+86.短信.facetime.imessage等问题.是ios7系统哦!(本人亲测iphone5 SB版 双模卡解锁)相当 ...

  10. C++文件读写详解(ofstream,ifstream,fstream)

    C++文件读写详解(ofstream,ifstream,fstream) 这里主要是讨论fstream的内容: #include <fstream> ofstream //文件写操作 内存 ...