当前位置: 首页 > 知识库问答 >
问题:

无法读取java中http post请求的表单数据

陆伟
2023-03-14
//...

Socket client = server.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));

System.out.println("Request:");

while ((line = in.readLine()) != null)
    if (line.length() > 0)
    System.out.println("\t" + line);
        else break;

in.close();
client.close();
Waiting for request...
Connection accepted.
Request:
    POST /form.php HTTP/1.1
    Host: x-x-x-x
    Connection: keep-alive
    Content-Length: 31
    Cache-Control: max-age=0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Origin: http://neviat.us.to
    User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
    Content-Type: application/x-www-form-urlencoded
    Referer: http://x-x-x-x
    Accept-Encoding: gzip,deflate,sdch
    Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
Connection closed.
Waiting for request...
Connection accepted.
Request:
    POST /buy.php HTTP/1.1
    Host: x-x-x-x
    Connection: keep-alive
    Content-Length: 31
    Cache-Control: max-age=0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Origin: http://neviat.us.to
    User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
    Content-Type: application/x-www-form-urlencoded
    Referer: http://x-x-x-x
    Accept-Encoding: gzip,deflate,sdch
    Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4

    // stop here, waiting for stream...

我怎么才能得到它?

共有1个答案

慕弘深
2023-03-14

更改:

if (line.length() > 0)

if (line.length() > -1)

长度为0的行完全有效

 类似资料:
  • 在这里,我使用HttpClient发布JSON数据。但是我无法读取其他应用程序上的数据。当我执行时,它会返回null。我的两个应用程序都部署在同一台服务器上。请告诉我我做错了什么。谢谢

  • 我的Firebase函数https请求有问题。 此外,当我在后端时,它只显示..一个空的物体。 有什么想法为什么似乎不起作用吗?我也使用和来实现,但它们都返回到故障安全。

  • 对传递的 URL 发出一个 POST 请求。 使用 XMLHttpRequest web api 对给定的url 发出一个 post 请求。 用 setRequestHeader 方法设置 HTTP 请求头的值。 通过调用给定的 callback 和 responseText 来处理 onload 事件。 通过运行提供的 err 函数,处理onerror事件。 省略第三个参数 data ,不发送数

  • 我需要一个java程序来生成以下请求。我正在使用Apache HttpClient Library,但仍然无法生成这样的请求: 这是我的python程序生成的,我编写了一个等效的java程序。但它扔403。 2012-09-10 15:12:05G信息:G2OAuth auth data=“3,0.0.0,0.0.0,1347289925,3223833979,crlakamai”2012-09-

  • 问题内容: 我似乎无法恢复发送到我的Node.js服务器的发布请求的表单数据。我在服务器代码和发布请求(在chrome中使用postman发送)的下方放置了: 发布请求 NodeJS服务器代码 登录方法尝试获取,但是始终为空。我在SO上看到过其他描述这种行为的案例,但是没有相关的答案在这里适用。 感谢您的帮助。 问题答案: 通常,快速应用程序需要指定适当的主体解析器中间件才能包含主体。 [编辑]

  • 我在Hive(beeline)中创建了一个表,下面的命令是: 我还有一个小的自定义文件,其中包含示例记录,如: 有什么想法吗?