NutzCN Logo
精华 Nutz中如何获取HttpServertRequest中的InputStram里的参数
发布于 2903天前 作者 Longitude 1685 次浏览 复制 上一个帖子 下一个帖子
标签:

Rt。

4 回复

你想要的是InputStream转Map? 还是php那种限定只能从 post body取参数

示例:

            NutMap qsMap = new NutMap();
            // 分析
            String qs = Streams.readAndClose(new InputStreamReader(ins));
           String[] ss = Strings.splitIgnoreBlank(qs, "[&]");
                for (String s : ss) {
                    Pair<String> p = Pair.create(s);
                    String val = p.getValue();
                    if (Strings.isBlank(val)) {
                        qsMap.put(p.getName(), true);
                    } else {
                        try {
                            val = URLDecoder.decode(val, Encoding.UTF8);
                        }
                        catch (UnsupportedEncodingException e) {
                            throw Lang.wrapThrow(e);
                        }
                        qsMap.put(p.getName(), val);
                    }
                }
            }

添加回复
请先登陆
回到顶部