java模拟http get和post 提交

使用Java模拟http请求.rar 使用Java模拟http请求.rar使用Java模拟http请求.rar 立即下载
使用httpclient工具包commons-httpclient-3.1.jar,依赖commons-logging-1.0.4.jar和commons-codec-1.3.jar。 
Java代码 复制代码  收藏代码
  1. import java.io.BufferedReader;   
  2. import java.io.IOException;   
  3. import java.io.InputStreamReader;   
  4. import java.util.Map;   
  5.   
  6. import org.apache.commons.httpclient.HttpClient;   
  7. import org.apache.commons.httpclient.HttpMethod;   
  8. import org.apache.commons.httpclient.HttpStatus;   
  9. import org.apache.commons.httpclient.URIException;   
  10. import org.apache.commons.httpclient.methods.GetMethod;   
  11. import org.apache.commons.httpclient.methods.PostMethod;   
  12. import org.apache.commons.httpclient.params.HttpMethodParams;   
  13. import org.apache.commons.httpclient.util.URIUtil;   
  14.   
  15. /**  
  16.  *   
  17.  *   
  18.  * <p>Title:HttpTookitEnhance</p>  
  19.  * <p>Description: httpclient模拟http请求,解决返回内容乱码问题</p>  
  20.  * <p>Copyright: Copyright (c) 2010</p>  
  21.  * <p>Company: </p>  
  22.  * @author libin  
  23.  * @version 1.0.0  
  24.  */  
  25. public class HttpTookitEnhance   
  26. {   
  27.       /**   
  28.        * 执行一个HTTP GET请求,返回请求响应的HTML   
  29.        *   
  30.        * @param url                 请求的URL地址   
  31.        * @param queryString 请求的查询参数,可以为null   
  32.        * @param charset         字符集   
  33.        * @param pretty            是否美化   
  34.        * @return 返回请求响应的HTML   
  35.        */  
  36.       public static String doGet ( String url, String queryString, String charset, boolean pretty )   
  37.       {   
  38.             StringBuffer response = new StringBuffer();   
  39.             HttpClient client = new HttpClient();   
  40.             HttpMethod method = new GetMethod(url);   
  41.             try  
  42.             {   
  43.                   if ( queryString != null && !queryString.equals("") )   
  44.                         //对get请求参数做了http请求默认编码,好像没有任何问题,汉字编码后,就成为%式样的字符串    
  45.                         method.setQueryString(URIUtil.encodeQuery(queryString));   
  46.                   client.executeMethod(method);   
  47.                   if ( method.getStatusCode() == HttpStatus.SC_OK )   
  48.                   {   
  49.                         BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), charset));   
  50.                         String line;   
  51.                         while ( ( line = reader.readLine() ) != null )   
  52.                         {   
  53.                               if ( pretty )   
  54.                                     response.append(line).append(System.getProperty("line.separator"));   
  55.                               else  
  56.                                     response.append(line);   
  57.                         }   
  58.                         reader.close();   
  59.                   }   
  60.             }   
  61.             catch ( URIException e )   
  62.             {   
  63.             }   
  64.             catch ( IOException e )   
  65.             {   
  66.             }   
  67.             finally  
  68.             {   
  69.                   method.releaseConnection();   
  70.             }   
  71.             return response.toString();   
  72.       }   
  73.   
  74.       /**   
  75.        * 执行一个HTTP POST请求,返回请求响应的HTML   
  76.        *   
  77.        * @param url         请求的URL地址   
  78.        * @param params    请求的查询参数,可以为null   
  79.        * @param charset 字符集   
  80.        * @param pretty    是否美化   
  81.        * @return 返回请求响应的HTML   
  82.        */  
  83.       public static String doPost ( String url, Map<String, String> params, String charset, boolean pretty )   
  84.       {   
  85.             StringBuffer response = new StringBuffer();   
  86.             HttpClient client = new HttpClient();   
  87.             HttpMethod method = new PostMethod(url);   
  88.             //设置Http Post数据    
  89.             if ( params != null )   
  90.             {   
  91.                   HttpMethodParams p = new HttpMethodParams();   
  92.                   for ( Map.Entry<String, String> entry : params.entrySet() )   
  93.                   {   
  94.                         p.setParameter(entry.getKey(), entry.getValue());   
  95.                   }   
  96.                   method.setParams(p);   
  97.             }   
  98.             try  
  99.             {   
  100.                   client.executeMethod(method);   
  101.                   if ( method.getStatusCode() == HttpStatus.SC_OK )   
  102.                   {   
  103.                         BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), charset));   
  104.                         String line;   
  105.                         while ( ( line = reader.readLine() ) != null )   
  106.                         {   
  107.                               if ( pretty )   
  108.                                     response.append(line).append(System.getProperty("line.separator"));   
  109.                               else  
  110.                                     response.append(line);   
  111.                         }   
  112.                         reader.close();   
  113.                   }   
  114.             }   
  115.             catch ( IOException e )   
  116.             {   
  117.             }   
  118.             finally  
  119.             {   
  120.                   method.releaseConnection();   
  121.             }   
  122.             return response.toString();   
  123.       }   
  124.   
  125.       public static void main ( String [] args )   
  126.       {   
  127.             String y = doGet("http://video.sina.com.cn/life/tips.html", null, "GBK", true);   
  128.             System.out.println(y);   
  129.       }   
  130.   
  131. } 
java模拟https基本jar包 java用于模拟https需要的jar包 包含commons-lang-2.6.jar、httpclient-4.3.2.jar、httpcore-4.3.jar、commons-io-2.4.jar、httpmime-4.3.1.jar、httpclient-cache-4.3.1.jar 立即下载

相关推荐

java httpclient 模拟登录

模拟登录 不提供用户名密码

深入解析MockServer:Java中的模拟HTTP服务器和客户端

MockServer是一个开源的模拟服务器,它可以模拟任何基于HTTP的系统。你可以使用MockServer来模拟复杂的系统响应,而无需搭建一个完整的服务。这对于微服务架构中的服务间通信、第三方API集成测试或任何需要模拟HTTP响应的情形都非常有用。

weixin_53840353的博客 1753

Java发送post,get请求

java模拟HTTP发送post和get请求工具类,使用httpClient类

java模拟调用get请求

import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.text.NumberFormat; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.ut..

NullToSay的踩坑日常 891

【实战】ComfyUI-Impact-Subpack插件安装与UltralyticsDetectorProvider节点修复全流程

本文详细解析了ComfyUI中UltralyticsDetectorProvider节点缺失的原因,并提供了完整的ComfyUI-Impact-Subpack插件安装与修复全流程。核心在于Impact Pack插件架构调整导致节点被拆分至子插件包。指南涵盖手动安装、依赖安全配置、模型文件管理及深度排错步骤,帮助用户彻底解决节点缺失问题,恢复工作流正常运行。

weixin_29290947的博客 438

matlab/simulink saw谐振器仿真,基于Matlab的SAW模态耦合模型的仿真研究

第32卷 第 4 期Vol. 32 No. 4重 庆 理 工 大 学 学 报 (自然科学)Journal of Chongqing University of Technology( Natural Science)2 0 1 8年 4 月Apr. 2018doi : 10.3969/j . issn. 1674-8425(z). 2018.04.002本文引用格式 :李志鹏,马龙祥,孟旭,等•基...

weixin_36192634的博客 1386

Java模拟http请求

Java实现http请求主要有3种方式:URLConnection、HttpURLConnection、HttpClient 一 URLConnection 抽象类,属于Java发送http请求的原生api,操作简单 1. 构造URL对象 2. 获取URL对应的URLConnection对象 3. 设置URLConnection的属性值 4. 获取输出流写入数据 5. 获取输...

fantasyleaves的博客 899

069_死区效应对输出电压畸变的补偿思路

死区效应导致逆变器输出电压在过零点出现台阶畸变,引发THD升高。其本质是死区期间续流二极管钳位造成的非线性误差,与电流方向、负载大小、母线电压耦合。补偿需结合前馈(基于电流方向自适应调整偏置)与反馈(抑制残余谐波),关键在于准确判断电流方向(采用滞环滤波避免跳变)、合理设置补偿量(随负载动态调整),并注意补偿位置、极性及限幅防漂移。调试应通过差分探头、FFT频谱等手段验证效果,最终实现全负载范围内的低畸变输出。

2401_88858637的博客 22

java 模拟get post请求_java端模拟http的get、post请求(转)

Servlet是SUN指定的Java服务器端编程规范,用以处理来自客户端的请求,处理并做出响应的一套基础API。Servlet是运行在Servlet容器中的Java小程序,容器运行在服务器端,服务器侦听特定端口的请求,并解析请求地址,将请求对象送给容器中的Servlet来执行,这个原理非常简单,平时我们多以在浏览器中输入URL地址,提交表单方式来实现,现在我们用Java语言来模拟常用的GET和PO...

weixin_32380307的博客 775

六、数据资产平台功能架构

该架构图展示了一个功能完善的数据资产平台,它涵盖了数据资产管理的各个方面,从数据采集、模型设计、编目到使用和分析。通过该平台,企业可以更好地管理数据资产,提高数据利用效率,并为业务决策提供有力支持。

moton2017的博客 1627

[个人自用,全网最优]EDEM-FLUENT个人自学教程,拒绝手忙脚乱无用功!

[个人自用,全网最优]EDEM-FLUENT个人自学教程,拒绝手忙脚乱无用功!

zheaa的博客 4828

Java模拟发送Http请求详细示例

对接第三方接口,肯定是需要我们自己模拟浏览器来发送请求的,有的文档中有demo,有demo改一改参数配置就好了,但有的接口却没有demo,只有一份接口参数介绍文档,这时候就需要我们自己来写发送请求的代码了。使用依赖 请求代码如下:......

weixin_47316183的博客 4319

基于 Spring Cloud 环境污染物数据分析与预测平台

基于 Spring Cloud 环境污染物数据分析与预测平台

935

java http 模拟提交post_Java模拟Http Get和Post 提交

本帖最后由 html580 于 2014-5-15 10:06 编辑在工具中有时我们要进行模态表单提交数据,现在给大家一个通过通过HttpURLConnection模拟Http Get和Post表单提交。相关文章: Java 使用HttpClient模拟 Http Get和Post 提交package com.html580.connection;import java.io.BufferedRe...

weixin_39607240的博客 218

2025华为od面试手撕代码【求字符串表达式结果】

2025华为od面试手撕代码【求字符串表达式结果】

MISAYAONE的博客 1353

YOLOv8改进-bifpn

跨尺度连接通过添加一个跳跃连接和双向路径来实现,自此实现了加权融合和双向跨尺度连接。该结构是加权且双向连接的,即自顶向下和自底向上结构,通过构造双向通道实现跨尺度连接,将特征提取网络中的特征直接与自下而上路径中的相对大小特征融合,保留了更浅的语义信息,而不会丢失太多的深层语义信息。传统的特征融合时将尺度不同的特征图以相同权重进行加权,但是当输入的特征图分辨率不同时,以相同的权重进行加权对输出的特征图不平等。所以BiFPN根据不同输入特征的重要性设置不同的权重,同时反复采用这种结构来加强特征融合。

weixin_45303602的博客 8139

java socket post_socket模拟http中post或者get提交数据,并获得响应数据

post提交模拟import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.net.InetAddress;import jav...

weixin_42364640的博客 710

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Java 使用 URLConnection 模拟 Http Get和Post 提交

Java 使用 URLConnection 模拟 Http Get和Post 提交 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URL; import

梦想起飞的地方......... 662

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

java模拟http get和post 提交 httpclient

原文地址:http://blog.youkuaiyun.com/miniyaner/article/details/12423435 原文post的处理不是很方便,本人对其进行了改造,下面为改造完后的代码: 使用httpclient工具包commons-httpclient-3.1.jar,依赖commons-logging-1.0.4.jar和commons-codec-1.3.jar。

木偶笔记 486

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

java httpclient教程_Java 使用HttpClient模拟 Http Get和Post 提交

package com.html580.connection;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.HashMap;import java.util.Map;import org.apache.commons.httpcli...

weixin_31739613的博客 301

HTTP通信模拟表单提交数据

前面记录过一篇关于http通信,发送数据的文章:http://www.cnblogs.com/hyyq/p/7089040.html,今天要记录的是如何通过http模拟表单提交数据。 一、通过GET请求方式提交:最简单的一种方式   直接在链接后面跟上要提交的数据即可,比如: http://yychf.55555.io/get.do?username=yyc&password=yychf,通过

caoliu1024cl的博客 2266
上一篇: Android 小项目之--Mini音乐播放器【简单版】
下一篇: eclipse中设置换行
hoyan_li
博客等级 码龄14年 5粉丝 43原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值