Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery ajax和java服务器,数据丢失_Java_Javascript_Jquery_Ajax_Localserver - Fatal编程技术网

jquery ajax和java服务器,数据丢失

jquery ajax和java服务器,数据丢失,java,javascript,jquery,ajax,localserver,Java,Javascript,Jquery,Ajax,Localserver,我有这样一个ajax函数 $.ajax({ type: "POST", url: "http://localhost:55556", data: "lots and lots of pie", cache: false, success: function(result)

我有这样一个ajax函数

   $.ajax({
                      type: "POST",
                      url: "http://localhost:55556",
                      data: "lots and lots of pie",
                      cache: false,
                      success: function(result)
                      {     
                        alert("sent");


                      },
                      failure: function()
                      {
                              alert('An Error has occured, please try again.');
                      }
              });
 clientSocket = AcceptConnection();

 inp = new BufferedReader(new InputStreamReader (clientSocket.getInputStream()));
 String requestString = inp.readLine();

 BufferedReader ed = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

   while(true){
          String tmp = inp.readLine();
          System.out.println(tmp);
     }
还有一个看起来像这样的服务器

   $.ajax({
                      type: "POST",
                      url: "http://localhost:55556",
                      data: "lots and lots of pie",
                      cache: false,
                      success: function(result)
                      {     
                        alert("sent");


                      },
                      failure: function()
                      {
                              alert('An Error has occured, please try again.');
                      }
              });
 clientSocket = AcceptConnection();

 inp = new BufferedReader(new InputStreamReader (clientSocket.getInputStream()));
 String requestString = inp.readLine();

 BufferedReader ed = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

   while(true){
          String tmp = inp.readLine();
          System.out.println(tmp);
     }
奇怪的是,当我发送我的ajax时,我的服务器通过使用system.out获得

Host: localhost:55556
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 20
Origin: null
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache  

问题是我发送的数据在哪里,哪里有很多馅饼?

数据应该在标题行之后的一个空行之后,但我认为问题是数据没有以换行符结尾,因此,您无法使用
.readLine()
方法读取它

在循环遍历标题行时,可以查找“Content Length”行并获得数据的长度。当您到达空白行时,停止使用<代码> .RealLoad()/<代码>。改为一次读取一个字符,读取“内容长度”标题指定的字符数。我认为您可以在中找到这方面的示例代码


如果可以的话,我建议你使用图书馆来帮助解决这个问题。我想政府可以帮上忙。请参阅。

如果它有助于成功:ajax中的函数(结果)()永远无法实现,因此它从不“发送”警报这似乎是非常可靠的建议,我会尝试一下