PHP: setting content length of MIME message -


i have build api in php returns request java coder. have done.

header("mime-version: 1.0".$eol); header("connection: keep-alive".$eol); header("accept-encoding: gzip, deflate".$eol); header("host: host".$eol.$eol); header("content-type: multipart/related; boundary...//not sure if can show boundary".$eol); echo $res; 

so, there main headers , $res variable bdy of response. form way.

$eol="\r\n"; $boundary = "boundary...//not sure if can show boundary";  $res="--".$boundary.$eol; $res .= "content-type: application/json".$eol; ob_start(); print_r($json); $result = ob_get_clean(); $data .= "content-length: ".strlen($result).$eol.$eol; $res.=$result; $res.=$eol.$eol; $res.="--".$boundary.$eol; ob_start(); readfile('/var/www/9292/inputphoto.jpg'); $result = ob_get_clean(); $res.="content-type: image/jpeg".$eol; $imagelength=strlen($result)+6; //i add +6 because of 3 $eol $res.=$eol; $res.=$result; $res.=$eol.$eol; $res.="--".$boundary.$eol; $res .= "content-type: application/octet-stream".$eol; ob_start(); readfile('/var/www/9292/1.etmpl'); $result = ob_get_clean();    $vectorlength=strlen($result)+6; $res .= "content-length: ".$vectorlength.$eol; $res.=$eol; $res.=$result; $res .= $eol.$eol; $res .= "--".$boundary."--".$eol; 

here output java coder received.

http/1.1 200 ok date: wed, 22 apr 2015 12:30:47 gmt server: apache/2.4.10 (debian) mime-version: 1.0 connection: keep-alive, keep-alive accept-encoding: gzip, deflate host: 99.999.999.99:99 keep-alive: timeout=5, max=100 transfer-encoding: chunked content-type: multipart/related; boundary=--boundary...//not sure if can show boundary  2d66 --boundary...//not sure if can show boundary content-type: application/json {json can't show here}  --boundary...//not sure if can show boundary content-type: image/jpeg content-length: 1917  ����jfif``��c *��^i _|�rd�he�8�h x}�)o�d�����ƭ�2i�u�i p�$�� content of picture ----1429705906426boundary--   --boundary...//not sure if can show boundary content-type: application/octet-stream content-length: 9222  h67a831e8-5f0 content of vector --boundary...//not sure if can show boundary 

rather strange don't have content length of json, set can see in code. can see strange 2d66 before first boundary. otherwise output fine, java coder can receive image, vector , json. receives mistake:

unexpected end of headers detected. higher level boundary detected or eof reached. 

as understand content-length wrong somewhere.anyone experienced mime can show me mistake?


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -