代码如下:
写道
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
public class HttpRequestUtils {
public static HttpResponse getHttpResponse(String url, Map<String, String> params) throws Exception{
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 2 * 60 * 100);
HttpConnectionParams.setSoTimeout(httpParameters, 2 * 60 * 100);
DefaultHttpClient client = new DefaultHttpClient(httpParameters);
HttpGet httpGet = new HttpGet(new URI(url));
for(Map.Entry<String, String> entry : params.entrySet()){
httpGet.setHeader(entry.getKey(), entry.getValue());
}
return client.execute(httpGet);
}
public static HttpURLConnection getUrlConnection(String url, int bufferSize) throws Exception{
URL target = new URL(url);
HttpURLConnection conn = (HttpURLConnection) target.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setChunkedStreamingMode(bufferSize);
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
conn.setRequestProperty("Charsert", "UTF-8");
conn.setRequestProperty("contentType", "UTF-8");
conn.setRequestProperty("timenow", String.valueOf(System.currentTimeMillis()));
return conn;
}
}
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
public class HttpRequestUtils {
public static HttpResponse getHttpResponse(String url, Map<String, String> params) throws Exception{
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 2 * 60 * 100);
HttpConnectionParams.setSoTimeout(httpParameters, 2 * 60 * 100);
DefaultHttpClient client = new DefaultHttpClient(httpParameters);
HttpGet httpGet = new HttpGet(new URI(url));
for(Map.Entry<String, String> entry : params.entrySet()){
httpGet.setHeader(entry.getKey(), entry.getValue());
}
return client.execute(httpGet);
}
public static HttpURLConnection getUrlConnection(String url, int bufferSize) throws Exception{
URL target = new URL(url);
HttpURLConnection conn = (HttpURLConnection) target.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setChunkedStreamingMode(bufferSize);
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
conn.setRequestProperty("Charsert", "UTF-8");
conn.setRequestProperty("contentType", "UTF-8");
conn.setRequestProperty("timenow", String.valueOf(System.currentTimeMillis()));
return conn;
}
}
public String sendPostXml(String url, String postXml) { StringBuffer sb = new StringBuffer(); BufferedReader reader = null; OutputStreamWriter out = null; try { HttpURLConnection con = HttpRequestUtils.getUrlConnection(url, postXml.length()); con.setRequestProperty("Pragma:", "no-cache"); con.setRequestProperty("Cache-Control", "no-cache"); con.setRequestProperty("Content-Type", "text/xml"); out = new OutputStreamWriter(con .getOutputStream()); out.write(new String(postXml.getBytes("UTF-8"))); out.flush(); out.close(); //获取post端的响应的数据 reader = new BufferedReader(new InputStreamReader(con .getInputStream())); String lines; while ((lines = reader.readLine()) != null) { lines = new String(lines.getBytes(), "UTF-8"); sb.append(lines); } reader.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ if (out != null) { try { out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (reader != null) { try { reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return sb.toString(); }
相关推荐
java http 发送xml报文(java发送xml报文实例+参数)java http 发送xml报文java http 发送xml报文(java发送xml报文实例+参数)
java http-post xml格式客户端请求代码
java实现 http post xml
HttpClient Post提交多文件及多个普通参数,已经封装成工具类。 需传入 要请求的url 普通参数map 例 map.put("param1","张三"); 需要传入的文件流map 其中key为文件名 服务端接收无乱码。
在JAVA中如何用SERVLET处理Http Post的表单请求xml
发送Post请求,内容格式为xml,并获取响应内容
NULL 博文链接:https://waynett.iteye.com/blog/1129581
调用webservice接口,利用post方式传参数,将返回的XML结果,利用xmldocument返回到页面中。
.net Post方式调用.net和java的webservice,用post方式提交xml请求
模拟post请求,php服务器,远程资源
http请求,传输方式以xml格式,可以以文件的方式传输,或以拼接字符串的方式请求http请求,传输方式以xml格式,可以以文件的方式传输,或以拼接字符串的方式请求
使用XMLHTTP POST 方式,实现远程请求
java 自动按键精灵程序,通过读取XML文件来完成,界面简单,易操作,并且付有说明书,能对像windows优化大师的未注册用户,校内网的开心农场的自动收获农作物等,
面向对象的思想方法已经非常流行了,在编程语言(例如java,js)中,都运用面向对象的编程思想。在XML中,就是要将网页也作为一个对象来操作和控制,我们可以建立自己的对象和模板。与对象进行交流,如何命令对象,...
封装了java调用.net的websevice接口,解决了soapaction报错和server not identified错误,使用soap1.1协议。
1、根据调用API必须遵循的协议规则,提交方式均采用post,提交和返回数据格式都为XML,根节点名为xml,字符统一采用UTF-8编码,签名算法使用MD5。 2、本次后台代码使用Java语言编写。由于微信支付要求传输方式必须...
Java模拟发送get请求 Java模拟发送post请求 HTTP工具 返回值统一为String,所以请求接口要注意为 返回为json或者xml的接口。
作为没用过工作流的一员,之前看过vue引入activiti工作流的案例,但是组件中存在很多问题,这个是我修改过并且成功调用,大家可以供参考,富含Java代码(Jfinal),后续出spring版本的, 前台版本vue4.0版本, ...
DWR.xml配置文件说明书 1、 建立dwr.xml 配置文件 任何一个dwr.xml的文件都需要包含DWR DOCTYPE的声明行,格式如下: <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" ...
2.commons-digester.jar:方便地将XML文档所定义的元素转化为JAVA对象。 3.commons-lang.jar; 4.commons-collection.jar包: 5.commons-io.jar包:FileUtil.readLine(),就在这个jar包。 6.commons-HttpClient.jar包...