HTML表单提交给出了400个错误的请求 [英] HTML form submit giving 400 bad request

查看:111
本文介绍了HTML表单提交给出了400个错误的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用POST方法向REST(eXist db)Web服务提交HTML表单.正常提交是给 400错误的请求

I'm submitting a HTML form to REST(eXist db) web service using POST method.A normal submission is giving 400 bad request

这是我的HTML代码

<html>
    <script type="text/javascript">
     /* function createXMLHttpRequest()
       {
        if( typeof XMLHttpRequest == "undefined" )
        XMLHttpRequest = function() 
         {
          try 
          { 
           return new ActiveXObject("Msxml2.XMLHTTP.6.0")
          } 
         catch(e) {}
          try 
          { 
           return new ActiveXObject("Msxml2.XMLHTTP.3.0")
          } 
         catch(e) {}
          try
          { 
          return new ActiveXObject("Msxml2.XMLHTTP") 
          } 
         catch(e) {}
          try 
          { 
          return new ActiveXObject("Microsoft.XMLHTTP") 
          } 
         catch(e) {}
         throw new Error( "This browser does not support XMLHttpRequest." )
      };
       return new XMLHttpRequest();
     }

var AJAX = createXMLHttpRequest();*/
function submitForm()
 {

    //AJAX.open("POST",'http://localhost:8899/exist/rest/db/xql/sample.xq');
   // AJAX.send(document.form.xmlData.value);
   document.form.submit();
 };
</script>
<head>  
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
 <form name='form' action="http://localhost:8899/exist/rest/db/xql/sample.xq"  enctype="text/plain" method="post">
   <input type="text" name="xmlData"/>
   <input type="button" value="Submit" onclick="submitForm()";>
 </form>
</body>
</html>

注释的代码是使用AJAX发送POST请求. 我捕获了http标头请求和表单提交和AJAX提交的响应 这些是请求标头:

The commented code is to send POST request using AJAX. I captured the http header request and response for form submit and AJAX submit These are the request headers:

HTML表单提交标头:

HTML form submit header:

(Request-Line)  POST /exist/rest/db/xql/sample.xq HTTP/1.1
Host    localhost:8899
User-Agent  Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Connection  keep-alive
Content-Type    text/plain
Content-Length  26

AJAX请求标头:

(Request-Line)  POST /exist/rest/db/xql/sample.xq HTTP/1.1
Host    localhost:8899
User-Agent  Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Connection  keep-alive
Content-Length  16
Content-Type    text/plain; charset=UTF-8
Origin  null
Pragma  no-cache
Cache-Control   no-cache

我没有弄清楚我的代码有什么问题. 我为此工作了两天,但我找不到任何解决方案. 请对此进行调查并提供解决方案.

Im not getting what's wrong in my code . Im working on this for 2 days but i din't find any solution. Please look into this and provide a solution.

先谢谢了.

推荐答案

但是您不使用Ajax POST发送任何参数吗?

But you aren't sending any parameters with the Ajax POST?

Ajax代码应如下所示:

The Ajax code should look something like this:

var xmlData=encodeURIComponent(document.getElementById("xmlData").value);
var parameters="xmlData="+xmlData;
AJAX.open("POST", "'http://localhost:8899/exist/rest/db/xql/sample.xq", true)
AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
AJAX.send(parameters)

这篇关于HTML表单提交给出了400个错误的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆