MethodTest.xhtml 4.9 KB

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