Java 使用$\u post[]
您好,我有向php服务器发送post的代码,但我无法使用$\u post变量获取de da 在java usign gzip压缩中:Java 使用$\u post[],java,php,json,post,gzip,Java,Php,Json,Post,Gzip,您好,我有向php服务器发送post的代码,但我无法使用$\u post变量获取de da 在java usign gzip压缩中: 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\",
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,但我不能使用像$\u POST['json']这样的$\u POST变量
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);
}