MethodTest.xhtml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <!DOCTYPE HTML>
  2. <html xmlns="http://www.w3.org/1999/xhtml"><head>
  3. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  4. <title>HTTP method test</title>
  5. <style type="text/css" media="screen">
  6. body {background:#eee; margin:0%; padding:0%; padding-top:0%; padding-left:1%}
  7. .cform {margin:0%; padding:0%; padding-top:0%; padding-left:2%;}
  8. h3 {margin:0%; padding:0%; padding-top:0%; padding-left:0%;}
  9. </style>
  10. <script type="text/javascript"><![CDATA[
  11. function getParams() {
  12. var result = {};
  13. var kvPairs = location.search.slice(1).split('&');
  14. kvPairs.forEach(
  15. function(kvPair) {
  16. kvPair = kvPair.split('=');
  17. result[kvPair[0]] = kvPair[1] || '';
  18. }
  19. );
  20. return result;
  21. }
  22. function load() {
  23. var params = getParams();
  24. method = params["method"];
  25. if (!method) {
  26. method = "GET";
  27. }
  28. var elem = document.getElementById('h1');
  29. elem.innerHTML = "HTTP method test page";
  30. document.getElementById("proto_http").checked = (window.location.protocol != "https:");
  31. document.getElementById("proto_https").checked = (window.location.protocol == "https:");
  32. document.getElementById("server").value = location.host;
  33. document.getElementById("resource").value = "path";
  34. document.getElementById("method_get").checked = true;
  35. document.getElementById("body_none").checked = true;
  36. }
  37. function getRadioValue(elmname) {
  38. var elms = document.getElementsByName(elmname);
  39. var len = elms.length;
  40. var ret = "";
  41. for (var i=0; i<len; i++) {
  42. if (elms[i].checked) {
  43. ret = elms[i].value;
  44. }
  45. }
  46. return ret;
  47. }
  48. function sendreq() {
  49. var proto = getRadioValue("protocol");
  50. var host = document.getElementById("server").value;
  51. var res = document.getElementById("resource").value;
  52. var addr = proto + "://" + host + "/" + res;
  53. var meth = getRadioValue("method");
  54. var body = getRadioValue("body");
  55. xmlhttp = new XMLHttpRequest();
  56. if (!xmlhttp) {
  57. alert("XMLHttpRequest not available");
  58. window.history.back()
  59. }
  60. xmlhttp.open(meth,addr,true);
  61. if (body != '*') {
  62. xmlhttp.setRequestHeader("Content-Length", body.length);
  63. } else {
  64. body = null;
  65. }
  66. xmlhttp.onreadystatechange = function()
  67. {
  68. var laddr = addr
  69. var lmeth = meth
  70. var blen = "\nWith " + body.length + " bytes body data"
  71. if (xmlhttp.readyState == 4)
  72. {
  73. alert(lmeth + " " + laddr + blen + "\n\nResponse: " + xmlhttp.status + "\n\n" + xmlhttp.responseText);
  74. }
  75. }
  76. xmlhttp.send(body);
  77. }
  78. ]]></script>
  79. </head><body onload="load()">
  80. <h1 id='h1'>Fatal error: Javascript not available!</h1>
  81. <h2>Usage</h2>
  82. <p>
  83. TODO: Description how to use this page.
  84. </p>
  85. <h2>Test parameters</h2>
  86. <form lass="cform">
  87. <h3>Protocol</h3>
  88. <input id="proto_http" type="radio" name="protocol" value="http" />http <br />
  89. <input id="proto_https" type="radio" name="protocol" value="https" />https
  90. <h3>Server</h3>
  91. <input id="server" type="text" name="server" value="" />
  92. <h3>Resource</h3>
  93. <input id="resource" type="text" name="resource" value="" />
  94. <h3>Method</h3>
  95. <!-- http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html -->
  96. <input id="method_opt" type="radio" name="method" value="OPTIONS" />OPTIONS <br />
  97. <input id="method_get" type="radio" name="method" value="GET" />GET <br />
  98. <input id="method_hea" type="radio" name="method" value="HEAD" />HEAD <br />
  99. <input id="method_pos" type="radio" name="method" value="POST" />POST <br />
  100. <input id="method_put" type="radio" name="method" value="PUT" />PUT <br />
  101. <input id="method_del" type="radio" name="method" value="DELETE" />DELETE <br />
  102. <input id="method_tra" type="radio" name="method" value="TRACE" />TRACE <br />
  103. <input id="method_con" type="radio" name="method" value="CONNECT" />CONNECT <br />
  104. <input id="method_mkc" type="radio" name="method" value="MKCOL" />MKCOL <br />
  105. <input id="method_pro" type="radio" name="method" value="PROPFIND" />PROPFIND <br />
  106. <input id="method_inv" type="radio" name="method" value="INVALID" />*INVALID*
  107. <h3>Body data</h3>
  108. <input id="body_none" type="radio" name="body" value="*" />*none* <br />
  109. <input id="body_10" type="radio" name="body" value="1234567890" />1234567890 <br />
  110. <h3>Submit</h3>
  111. <input id="send" type="button" onclick="sendreq()" value="Send request" />
  112. </form>
  113. </body></html>