java后台调用url
版权声明:本文为博主牟云飞原创文章,未经博主同意不得转载。 https://blog.csdn.net/myfmyfmyfmyf/article/details/32690757
QXOutStream outPut= new QXOutStream();
qxWorkSheetXML.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?
>");
qxWorkSheetXML.append("<ROOT><ROW>");
qxWorkSheetXML.append("<REPORT_MAN>"+call_man+"</REPORT_MAN>");
qxWorkSheetXML.append("<ACCEPT_TIME>"+call_time+"</ACCEPT_TIME>");
qxWorkSheetXML.append("<CUSTOMER_CODE>"+workSheetNo+"</CUSTOMER_CODE>");
qxWorkSheetXML.append("<PHONE>"+call_no+"</PHONE>");
qxWorkSheetXML.append("<DEAL_DATE>"+deadLine+"</DEAL_DATE>");
qxWorkSheetXML.append("</ROW></ROOT>");
returnStr=outPut.outPutStr(urlStr, qxWorkSheetXML.toString());
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import XmlHelper;
public class QXOutStream {
public String outPutStr(String urlStr, String input) throws Exception{
StringBuffer strBuf = new StringBuffer();
String Resulst="";
try{
URL url = new URL(urlStr);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setAllowUserInteraction(false);
con.setUseCaches(false);
con.setRequestProperty("Accept-Charset", "GBK");
BufferedOutputStream bufOutPut = new BufferedOutputStream(con.getOutputStream());
byte[] bdat = input.getBytes("UTF-8");//解决中文乱码问题
bufOutPut.write(bdat, 0, bdat.length);
bufOutPut.flush();
BufferedInputStream inp = new BufferedInputStream(con.getInputStream());
InputStreamReader in = new InputStreamReader(inp,Charset.forName("GBK"));
BufferedReader bufReador = new BufferedReader(in);
String tempStr = "";
while (tempStr != null) {
strBuf.append(tempStr);
tempStr = bufReador.readLine();
}
Resulst = XmlHelper.getPostNodeText(strBuf.toString(), "OPERATOR_RESULT");//.getPostFirstRowText(strBuf.toString(), "OPERATOR_RESULT");
}
catch (Exception e) {
//System.err.println("Exception:"+e.toString());
throw e;
//return "N";
}
finally{
return Resulst;
}
}
}
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.transform.TransformerException;
import org.apache.log4j.Logger;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sun.org.apache.xpath.internal.XPathAPI;
/**
* 处理XML的封装类
*/
public abstract class XmlHelper {
private XmlHelper() {
}
private static SimpleXmlParser parser = new SimpleXmlParser();
private static Logger logger = Logger.getLogger(XmlHelper.class.getName());
public static Document getDocument(String xmlStr) throws Exception {
try {
return parser.parseXml(xmlStr);
} catch (Exception ex) {
logger.error("得到Document出错-->", ex);
throw ex;
}
}
public static Document getDocumentFormStream(InputStream s)
throws Exception {
try {
Document doc = parser.parse(s);
return doc;
} catch (Exception ex) {
logger.error("从文件流中得到Document出现错误,错误为-->", ex);
throw ex;
}
}
public static Document getDocumentFormFile(String url) {
try {
URL u = new URL(url);
URLConnection connection = u.openConnection();
connection.setDoInput(true);
connection.setUseCaches(false);
Document doc = parser.parse(url);
connection.getInputStream().close();
return doc;
} catch (Exception ex) {
logger.info("从url中取得数据出错,错误为-->", ex);
}
return null;
}
public static NodeList selectNodeList(Node node, String xpath)
throws TransformerException {
try {
return XPathAPI.selectNodeList(node, xpath);
} catch (TransformerException ex) {
logger.error("得到xml节点队列出错-->", ex);
throw ex;
}
}
public static Node selectSingleNode(Node node, String xpath)
throws TransformerException {
try {
return XPathAPI.selectSingleNode(node, xpath);
} catch (TransformerException ex) {
logger.error("得到单一的xml节点出错-->", ex);
throw ex;
}
}
public static Node selectNode(Node node, String xpath) {
for (int i = 0; i < node.getChildNodes().getLength(); i++) {
Node childNode = node.getChildNodes().item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE
&& childNode.getNodeName().equals(xpath))
return childNode;
}
return null;
}
public static Attr getAttribute(Node node, String attName) {
return (Attr) node.getAttributes().getNamedItem(attName);
}
public static String getNodeText(Node node) {
for (int i = 0; i < node.getChildNodes().getLength(); i++) {
if (node.getChildNodes().item(i).getNodeType() == Node.TEXT_NODE)
return node.getChildNodes().item(i).getNodeValue();
}
return null;
}
public static String getPostNodeText(String postString, String nodeName) {
try {
Document doc = getDocument(postString);
Element root = doc.getDocumentElement();
NodeList list = root.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
logger.debug("node:" + node.getNodeType() + ","
+ node.getNodeName());
if (node.getNodeName().equals(nodeName))
return getNodeText(node);
}
}
} catch (Exception ex) {
logger.error("从post信息中得到xml解析数据出错-->", ex);
}
return null;
}
public static String getPostFirstRowText(String postString, String nodeName) {
try {
return XmlHelperJdom.getFirstRowData(postString, nodeName);
} catch (Exception ex) {
logger.error("从post的第一行数据中得到xml解析数据出错-->", ex);
}
return null;
}
/*
* 加入一个节点,而且设置其text
*/
public static org.dom4j.Element addElementAndSetValue(
org.dom4j.Element parent, String name, String value) {
if (null == name)
return null;
org.dom4j.Element e = parent.addElement(name);
if (null == value) {
value = "";
}
e.setText(value);
return e;
}
}
java后台调用url的更多相关文章
- java后台调用url无协议
url格式不正确,可能有"www.baidu.com" "这个不能有 // 下载pdf public void downpdf(String URL, String ...
- 获取ip ,百度地图坐标点 和 在 后台调用 url()
protected void getip() { string ips = HttpContext.Current.Request.UserHostA ...
- 解决Jsp与Java后台之间url传值中文乱码问题
JSP页面中,由JavaScript拼接url时,对于中文名称变量应该加上encodeURIComponent方法,对中文进行十六进制编码. 例如: url = /com/xxx/B.jsp?chin ...
- java后台调用HttpURLConnection类模拟浏览器请求(一般用于接口调用)
项目开发中难免遇到外部接口的调用,小生今天初次接触该类,跟着API方法走了一遍,如有不对的地方,还请哆哆指正,拜谢! 1 package com.cplatform.movie.back.test; ...
- Java后台调用gcc编译C语言代码
想做一个能够在线编译代码运行的平台,Java和SQL已经支持了,因为是用Java写的后台,所以Java和SQL挺容易就实现了,做到支持C的时候就卡住了,网上搜了一下这种帖子好像很少. 我采取的办法是就 ...
- java后台调用http请求
1:代码 @Value("${sms.username}") 可以将sms.properties配置文件中的值注入到username //这种方式是将sms.properti ...
- md5签名加密(用于java 后台调用短信平台接口实现发短信)
MD5Util 方法 package com.funcanteen.business.action.pay.util; import java.security.MessageDigest; publ ...
- java后台调用文件上传接口
借鉴:https://blog.csdn.net/yjclsx/article/details/70675057 /** * 调用流程上传文件接口上传文件 * @param url * @param ...
- java后台获取URL带参demo
URL:http://aos.wall.youmi.net/v2/check_fb_sig?order=YM130402cygr_UTb42&app=30996ced018a2a5e& ...
随机推荐
- Confluence 6 自动添加用户到用户组
默认组成员(Default Group Memberships) 选项在 Confluence 3.5 及后续版本和 JIRA 4.3.3 及后续版本中可用.这字段将会在你选择 'Read Only, ...
- luogu P2408 不同子串个数
考虑反向操作,去计算有多少组相同的子串,对于一组大小为k的极大相同子串的集合,ans-=k-1. 为了避免重复计算,需要一种有效的,有顺序的记录方案. 比如说,对于每一个相同组,按其起始点所在的位置排 ...
- in_array的效率
in_array函数是个糟糕的选择.应该尽量用isset函数或array_key_exists函数来替代 .in_array函数的复杂度是O(n),而isset函数的复杂度是O(1) isset函数是 ...
- arcTo
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> < ...
- Intel daal4py demo运行过程
daal安装(记得先安装anaconda): git clone https://github.com/IntelPython/daal4py.git cd daal4py conda create ...
- elasticsearch term match multi_match区别
转自:http://www.cnblogs.com/yjf512/p/4897294.html match 最简单的一个match例子: 查询和"我的宝马多少马力"这个查询语句匹配 ...
- Java多线程的同步控制记录
Java多线程的同步控制记录 一.重入锁 重入锁完全可以代替 synchronized 关键字.在JDK 1.5 早期版本,重入锁的性能优于 synchronized.JDK 1.6 开始,对于 sy ...
- LTrim、RTrim 和 Trim 函数
返回不带前导空格 (LTrim).后续空格 (RTrim) 或前导与后续空格 (Trim) 的字符串副本. LTrim(string) RTrim(string) Trim(string) strin ...
- 安装淘宝cnpm镜像
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
- MySQL 5.7 分区表性能下降的案例分析
转载自:https://mp.weixin.qq.com/s/K3RpSBAIWFwGCIWyfF0QPA 前言:希望通过本文,使MySQL5.7.18的使用者知晓分区表使用中存在的陷阱,避免在该版本 ...