zoukankan      html  css  js  c++  java
  • 向RESTful web 服务发送XML请求示例

    做好了RESTful web 服务后,可以通过很多种方式向服务发起请求,本文仅介绍最简单的XMLHttpRequest发起请求方式。

    客户端脚本如下:

    <script type="text/javascript">
     
            var xmlHttp 
    = null; var url = ""; var content = "";
     
            function PostXML() {
                xmlHttp.onreadystatechange 
    = show;
                xmlHttp.open(
    "POST", url);
                xmlHttp.setRequestHeader(
    "Content-Type""application/xml");
                xmlHttp.send(content);
            }
            function show() {
                
    if (xmlHttp.readyState == 4) {
                    
    if (xmlHttp.status == 200) {
                        $(
    "#txtResult").val(xmlHttp.responseText);
                    }
                    
    else {
                        $(
    "#txtResult").val(xmlHttp.status.toString() + ":" + xmlHttp.statusText);
                    }
                }
            }
     
            window.onload 
    = function() {
               
    if (window.XMLHttpRequest) {
                    xmlHttp 
    = new XMLHttpRequest();
                }
                
    else if (window.ActiveXObject) {
                    xmlHttp 
    = new ActiveXObject("Microsoft.XMLHttp");
                }
                url 
    = $("#txtURL").val();
                content 
    = $("#txtRequest").val();
            }
        
    </script>

    请求格式为:

    <?xml version="1.0"?>
    <VisitCostRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" IndicationCode="indic" PatientStatus="1" TrialPhase="2" VisitCount="10">
      
    <Country>
        
    <Code>ddd</Code>
      
    </Country>
    </VisitCostRequest>

    最终,通过页面控件调用PostXML方法即可。

    文章出处:www.cnblogs.com/jizhong

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。否则保留追究法律责任的权利。

  • 相关阅读:
    错题记录——关于Java中private的用法(类与封装)
    深度学习-人脸识别-数据集和制作
    UE4使用经验记录
    pycharm 一直索引或索引过大占用系统盘问题
    深度学习portoch笔记_概念随笔
    mysql 找不到请求的 .Net Framework Data Provider。可能没有安装。
    halcon崩溃/异常信号11 后文件临时存储路径
    halcon 错误记录
    visual studio 2012 C#exe嵌入到子窗口,程序退出后子exe文件仍然被占用
    文件操作
  • 原文地址:https://www.cnblogs.com/jizhong/p/2032869.html
Copyright © 2011-2022 走看看