MethodTest.xhtml 5.7 KB

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