drvkf88226 2015-04-17 10:19
浏览 60

从Java和PHP中以字节为单位解析后请求的问题

I have rather complicated situation. I've previosly created some questions but now I'm closer to solution. Situation: Java coder sends me a request with picture. Here I receive his request and put it into log file:

$query = fopen("php://input",'rb');
$queryFile= fopen("/var/www/9292/querylog.txt","wb");
stream_copy_to_stream($query, $queryFile);
fclose($queryFile);
fclose($query);

Data from log is hexdecimal, so I handle it this way:

$query=file_get_contents("/var/www/9292/querylog.txt");
$query = preg_replace('/[\s
]+/', '', $query);
$queryHex=pack("H*", $query);
$inputImage=$queryHex;
$inputImage=trim($inputImage);

I don't know if I need to remove blanks, but removing and adding doesn't make changes in result. Then I create Image.

$imageFile=fopen("/var/www/9292/inputPhoto.jpg", 'wb');
fwrite($imageFile, $inputImage);
fclose($imageFile);

So, the problem: when Java coder sends a request, created picture is half-size and unreadable, but when I put data from log into Advanced Rest Client and use the same script it creates fine photo. I've got tcpdump oh his request. Here it is and it something like:

......JFIF.....`.`.....C......
..
......(.....1#%.(:3=<9387@H\N@DWE78PmQW_bghg>Mqypdx\egc...C......./../cB8Bcccccccccccccccccccccccccccccccccccccccccccccccccc........p.."......................................6......................!..1.A."Qa2q...B....#4Ccr......................................................A.1............?..j*i.}.+vE..s...d85..5.....K..`..hc..y..=@.3.|N.<...?.......h....Y.$.5....W%....?E..cm0..$.$...I$...s...... Z.P2.3.j9..I..w\..F.......1.c.{.?\~..>.m4.......E......{.).nm"B.|....u..........[.H..>..4.~...k.pl......KO..;z/K..S4./.6i.....OpEc...'.m..0k9Y.r.......e. n........>...8.........~.X.R...h...f.."...q...../..mmn.<..\NI?2..q...O.2nd!......A=...\7.qZ.YS..,.+q.....

(I don't show whole photo because of privacy=)). Now when I check a script with Advanced Rest Client and put there picture in binary it: 1. Puts data into log in binary format 2. Creates the same picture like Java coder request does.

So as I understand I should handle request in some other way. So, how can I handle it to get fine picture?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c