post方式发送和解析xml
来源:互联网 发布:软件测试新手入门 编辑:程序博客网 时间:2024/06/01 08:54
public void etcauthorize(String authCode, String clientState) { logger.info("CMCasController- etcauthorize start... "); View view = new View(SUCCESS); PostMethod myPost = null; try { StringBuffer xmlparam = new StringBuffer(); xmlparam.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") .append("<GetAccessTokenReqest xmlns=\"http://www.chinamobile.com.cn/schema/omp/idmp/v1_0\">") .append("<grantType>authorization_code</grantType>") .append("<clientId>" + appid + "</clientId>") .append("<clientSecret>" + clientSecret + "</clientSecret>") .append("<authCode>" + authCode + "</authCode>") .append("<redirectUri>" + URLEncoder.encode(PageUtil.parseUrl(redirectUri), "utf-8") + "</redirectUri>") .append("<display>mobile</display>") .append("</GetAccessTokenReqest>"); logger.info("CMCasController- etcauthorize 跳转到中移動授权页面 請求 ", xmlparam.toString()); HttpClient httpclient = new HttpClient(); myPost = new PostMethod("https://open.mmarket.com/omee-aus/services/GetAccessToken"); myPost.setRequestHeader("Content-Type","text/xml"); myPost.setRequestHeader("charset","utf-8"); myPost.setRequestBody(xmlparam.toString());// 这里添加字符串 int resultcode = httpclient.executeMethod(myPost); if (resultcode == 200) { String res = myPost.getResponseBodyAsString(); logger.info("CMCasController- etcauthorize 跳转到中移動授权页面响应", res); if (res != null) { //创建新的字符串 StringReader read = new StringReader(res); //创建新的输入源SAX 解析器将使用 InputSource 对象来确定如何读取 XML 输入 InputSource source = new InputSource(read); //Dom方式解析xml DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document d = db.parse(source); String accessToken = d.getElementsByTagName("accessToken").item(0).getFirstChild().getNodeValue(); String uniqueId = d.getElementsByTagName("uniqueId").item(0).getFirstChild().getNodeValue(); logger.info("CMCasController-etcauthorize 获取到用户授权,accessToken:{}, uniqueId:{}" ,accessToken,uniqueId ); view.bind("show",getUserInfo(accessToken, uniqueId)); } } } catch (Exception e) { logger.error("CMCasController- etcauthorize 跳转到中移動授权页面 出现异常 ", e); } finally { // 释放连接 myPost.releaseConnection(); } this.render(view); }
阅读全文
0 0
- post方式发送和解析xml
- POST方式发送XML数据
- HttpWebRequest Post 方式发送 XML数据
- http post方式发送xml格式消息
- php接受xml和发送(post)xml
- php接受xml和发送(post)xml
- php接受xml和发送(post)xml
- 通过http/https的POST方式,发送和接受XML文件内容
- 通过http/https的POST方式,发送、处理和接收XML文件内容
- post和get方式发送数据
- Http GET和Http Post发送方式
- java通过post方式发送接收xml信息
- php用array创建xml并且 post 发送 ,PHP解析
- 后台post发送XML
- post 发送xml
- POST方式发送数据
- post方式发送数据
- C#模拟Post和Get方式发送数据 保持COOKIE
- battery-historian工具的使用
- android O 如何实现数据关闭时 发送彩信
- Python高效编程-对字典的值进行排序
- C++ 学习系列(三) #if #elif #else 和 #endif指令
- 在 SegmentFault,解决技术问题
- post方式发送和解析xml
- C语言中申请堆内存断点及其他常见问题
- Python—numpy模块下函数介绍(一)numpy.ones、empty等
- JSON.parse()和JSON.stringify()--json对象<=>字符串
- C#托管和非托管的资源(六)——平台调用
- 数字塔
- 苹果自带样式覆盖
- come on翻开新篇章
- 《中国金融集成电路(IC)卡规范第6部分(借记贷记应用终端规范)》--笔记