Java coder sends me some data (some headers and content of picture). It look like this:
436f 6e74 656e 742d 4c65 6e67 7468 3a20
3138 3830 0d0a 0d0a ffd8 ffe0 0010 4a46
4946 0001 0101 0060 0060 0000 ffdb 0043
0010 0b0c 0e0c 0a10 0e0d 0e12 1110 1318
281a 1816 1618 3123 251d 283a 333d 3c39
3338 3740 485c 4e40 4457 4537 3850 6d51
...
I'm trying to parse it with $queryHex=pack("H*", $query);
where $query = file_get_contents("php://input");
When I try to var_dump $queryHex
I get
Co�@enB�Le�pth�18�
and than some not readable symbols that I suppose to be a content of picture.
Also I tried to set encoding (header('Content-Type: text/html; charset=utf-8');
) and result remains.
What I'm doing wrong? How to get propper data?
Update: According to his API he should send something like this:
POST /url_for_detect HTTP/1.1
Content-Type: image/jpeg; boundary=-
[DATA]
DATA is a content of picture. But there is Content-length there. He said that it's not necessary. However I stil can't see content-type there or get DATA. Asked him to send me a query that he sends.
The bytes you posted contains.
Content-Length: 1880
FF D8 FF E0 00 10 4A 46 49 46 <-- the start of the JPEG file
As @awons suggested already. Ask the sender what he send to you.
edit
Small "quick'n'dirty" code to convert the bytes into binary.
String content = "436f 6e74 656e 742d 4c65 6e67 7468 3a20"
+ "3138 3830 0d0a 0d0a ffd8 ffe0 0010 4a46"
+ "4946 0001 0101 0060 0060 0000 ffdb 0043"
+ "0010 0b0c 0e0c 0a10 0e0d 0e12 1110 1318"
+ "281a 1816 1618 3123 251d 283a 333d 3c39"
+ "3338 3740 485c 4e40 4457 4537 3850 6d51";
StringBuilder sb = new StringBuilder(content.replaceAll(" ", ""));
sb.delete(0, 48); // remove "Content-Length: 1880"
try (FileOutputStream fos = new FileOutputStream("content.jpg")) {
while (sb.length() > 2) {
fos.write(Integer.parseInt(sb.substring(0, 2), 16));
sb.delete(0, 2);
}
}