привет, у меня есть код с отправкой сообщения на php-сервер, но я не могу получить ответ с переменной $ _POST
в java usign gzip compress:
public static void main(String[] args){
String foo = "[{\"0\":\"12234107\",\"1\":\"2012-01-27 12:59:36.227\",\"2\":\"OXP\",\"3\":\"CUCH-93717\",\"4\":\"1\",\"5\":\"CERRADA\",\"6\":\"OXPD145\",\"7\":\"2012-01-27 13:01:09.467\",\"8\":\"UNACK_ALM\"}]";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null;
HttpClient httpclient = null;
HttpResponse response;
System.out.println(foo.length());
try {
httpclient = new DefaultHttpClient();
HttpPost httppost= new HttpPost ("http://127.0.0.1/lab/proyectos/php/java_envio_mensajes/post_json_gzip.php");
byte[] bgzip = gzip(foo);
InputStreamEntity httpentity = new InputStreamEntity(new ByteArrayInputStream(bgzip), bgzip.length);
httpentity.setChunked(true);
httppost.setEntity(httpentity);
response=httpclient.execute(httppost);
httppost.setEntity(httpentity);
...
}
}
public static byte[] gzip(String foo){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos = null;
try {
gzos = new GZIPOutputStream(baos);
gzos.write(foo.getBytes("UTF-8"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (gzos != null) try { gzos.close(); } catch (IOException ignore) {};
}
return baos.toByteArray();
}
на стороне php, используя gzinflate, но я не могу использовать переменные $ _POST, такие как $ _POST ['json']
function logToFile($filename,$msg){
$fd=fopen($filename,"a");
$str="[".date("Y/m/d h:i:s")."]".$msg;
fwrite($fd,$str."\n");
fclose($fd);
}
$input = file_get_contents('php://input');
if(isset($input)){
$response = gzinflate(substr($input, 10));
logToFile("post.txt",$response);
}