doupapin172773
2017-04-25 15:56
浏览 199
已采纳

PHP从Java DataOutputStream读取输入流?

For a while, I've been working on a Java client that sends level information to save online. I have managed using printwriter, but it is really inefficient, and a simple 300KB level turns out to be 3MB after the transfer, and is rather slow.

I know people have used "file_get_contents("php://input")", such as in receive output from java DataOutputStream in a php page, but I am not sure how to receive specific data from:

//phpsend is the DataOutputStream using POST (java)
phpsend.writeUTF(username);
phpsend.writeUTF(verificationId);
phpsend.writeInt(levelsize);
phpsend.write(level); //level has been converted to a byte array

how would I read each separate write? I know Java had DataInputStream, which had all the corresponding read functions, but how would I do that in PHP? I've heard of "Sockets" and "SOAPClient", but I could not find any information that I could use

图片转代码服务由CSDN问答提供 功能建议

有一段时间,我一直在研究一个发送级别信息以在线保存的Java客户端。 我使用printwriter进行了管理,但效率非常低,传输后简单的300KB级别变为3MB,速度相当慢。

我知道人们使用了“file_get_contents”( “php:// input”)“,例如在收到 来自php页面中的java DataOutputStream的输出,但我不确定如何从以下方式接收特定数据:

  // phpsend是使用POST的DataOutputStream(java)  
phpsend.writeUTF(用户名); 
phpsend.writeUTF(verificationId); 
phpsend.writeInt(levelsize); 
phpsend.write(电平);  // level已被转换为字节数组
   
 
 

我将如何读取每个单独的写入? 我知道Java有DataInputStream,它有所有相应的读取函数,但是我如何在PHP中做到这一点? 我听说过“套接字”和“SOAPClient”,但我找不到任何可以使用的信息

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsh77114 2019-03-24 18:35
    已采纳

    So I have found that

    file_get_contents("php://input")
    

    seems to do the what I want. Simply assign its result to a variable

    $data = file_get_contents("php://input");
    

    and the $data get all Java sent.

    点赞 评论

相关推荐 更多相似问题