MethodTest.xhtml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 noBody() {
  23. document.getElementById("body_none").checked = true;
  24. }
  25. function load() {
  26. var params = getParams();
  27. var method = params["method"];
  28. if (!method) {
  29. method = "GET";
  30. }
  31. var path = params["path"];
  32. if (!path) {
  33. path = "";
  34. }
  35. var elem = document.getElementById('h1');
  36. elem.innerHTML = "HTTP method test page";
  37. document.getElementById("proto_http").checked = (window.location.protocol != "https:");
  38. document.getElementById("proto_https").checked = (window.location.protocol == "https:");
  39. document.getElementById("server").value = location.host;
  40. document.getElementById("resource").value = path;
  41. setRadioValue("method", method);
  42. noBody();
  43. }
  44. function setRadioValue(elmname, value) {
  45. var elms = document.getElementsByName(elmname);
  46. var len = elms.length;
  47. var ret = false;
  48. for (var i=0; i<len; i++) {
  49. elms[i].checked = (elms[i].value == value);
  50. ret |= elms[i].checked;
  51. }
  52. return ret;
  53. }
  54. function getRadioValue(elmname) {
  55. var elms = document.getElementsByName(elmname);
  56. var len = elms.length;
  57. var ret = "";
  58. for (var i=0; i<len; i++) {
  59. if (elms[i].checked) {
  60. ret = elms[i].value;
  61. }
  62. }
  63. return ret;
  64. }
  65. function sendreq() {
  66. var proto = getRadioValue("protocol");
  67. var host = document.getElementById("server").value;
  68. var res = document.getElementById("resource").value;
  69. var addr = proto + "://" + host + "/" + res;
  70. var meth = getRadioValue("method");
  71. var body = getRadioValue("body");
  72. xmlhttp = new XMLHttpRequest();
  73. if (!xmlhttp) {
  74. alert("XMLHttpRequest not available");
  75. window.history.back()
  76. }
  77. xmlhttp.open(meth,addr,true);
  78. if (body != '*') {
  79. xmlhttp.setRequestHeader("Content-Length", body.length);
  80. } else {
  81. body = null;
  82. }
  83. xmlhttp.onreadystatechange = function()
  84. {
  85. var laddr = addr
  86. var lmeth = meth
  87. var blen = ""
  88. if (body) {
  89. blen = "\nWith " + body.length + " bytes body data"
  90. }
  91. if (xmlhttp.readyState == 4)
  92. {
  93. alert(lmeth + " " + laddr + blen + "\n\nResponse: " + xmlhttp.status + "\n\n" + xmlhttp.responseText);
  94. }
  95. }
  96. xmlhttp.send(body);
  97. }
  98. ]]></script>
  99. </head><body onload="load()">
  100. <h1 id='h1'>Fatal error: Javascript not available!</h1>
  101. <h2>Usage</h2>
  102. <p>
  103. TODO: Description how to use this page.
  104. </p>
  105. <h2>Test parameters</h2>
  106. <form lass="cform">
  107. <h3>Protocol</h3>
  108. <input id="proto_http" type="radio" name="protocol" value="http" />http <br />
  109. <input id="proto_https" type="radio" name="protocol" value="https" />https
  110. <h3>Server</h3>
  111. <input id="server" type="text" name="server" value="" />
  112. <h3>Resource</h3>
  113. <input id="resource" type="text" name="resource" value="" />
  114. <h3>Method</h3>
  115. <!-- http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html -->
  116. <input id="method_opt" type="radio" name="method" value="OPTIONS" />OPTIONS <br />
  117. <input id="method_get" type="radio" name="method" value="GET" />GET <br />
  118. <input id="method_hea" type="radio" name="method" value="HEAD" />HEAD <br />
  119. <input id="method_pos" type="radio" name="method" value="POST" />POST <br />
  120. <input id="method_put" type="radio" name="method" value="PUT" />PUT <br />
  121. <input id="method_del" type="radio" name="method" value="DELETE" />DELETE <br />
  122. <input id="method_tra" type="radio" name="method" value="TRACE" />TRACE <br />
  123. <input id="method_con" type="radio" name="method" value="CONNECT" />CONNECT <br />
  124. <input id="method_mkc" type="radio" name="method" value="MKCOL" />MKCOL <br />
  125. <input id="method_pro" type="radio" name="method" value="PROPFIND" />PROPFIND <br />
  126. <input id="method_inv" type="radio" name="method" value="INVALID" />*INVALID*
  127. <h3>Body data</h3>
  128. <input id="body_none" type="radio" name="body" value="*" />0 Bytes <br />
  129. <input id="body_10" type="radio" name="body" value="1234567890" />10 Bytes ("1234567890") <br />
  130. <h3>Submit</h3>
  131. <input id="send" type="button" onclick="sendreq()" value="Send request" />
  132. </form>
  133. </body></html>