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. Sum Root to Leaf Numbers

    int sumNumbers(TreeNode *root) { ); } int dfs(TreeNode *root, int sum) { ; if (root->left == null ...

  2. 【Hibernate】Hibernate系列5之检索策略

    检索策略 5.1.类级别检索策略 5.2.set多对多.一对多检索策略 5.3.多对一.一对一检索策略 HQL作用: http://zhidao.baidu.com/link?url=dnAdJWR7 ...

  3. 设置windows网络连接别名和linux网络连接别名

    windows网络连接别名 C:\Windows\System32\drivers\etc目录下的hosts文件中添加 127.0.0.1 localhost 192.168.1.100 proxy. ...

  4. iOS viewDidAppear 和 viewWillAppear

    今天发现,如果用navigation push一个controller,那么从动画开始就调用viewwillappear,动画全部停止才会调用viewDidAppear,不知道是否正确,先做记录,带验 ...

  5. Java for LeetCode 075 Sort Colors

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  6. hdu 1113 Word Amalgamation 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...

  7. SQLHelper、DBUtil终极封装

    DBUtil.java package org.guangsoft.util; import java.io.InputStream; import java.sql.Connection; impo ...

  8. ubuntu 图形界面查看隐藏文件

    在 Linux 下以 . 开头的文件或文件夹为隐藏文件,在图形界面(nautilus)下可用 CTRL + H 显示隐藏文件,终端下者可以用 ls -a 显示所有文件.

  9. InnoDB引擎的索引和存储结构

    在Oracle 和SQL Server等数据库中只有一种存储引擎,所有数据存储管理机制都是一样的.而MySql数据库提供了多种存储引擎.用户可以根据不同的需求为数据表选择不同的存储引擎,用户也可以根据 ...

  10. ytu 1938:首字母变大写(水题)

    首字母变大写 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 110  Solved: 43[Submit][Status][Web Board] Desc ...