有没有简单的小程序 url 生成器?

发布于 2024-12-08 20:53:30 字数 252 浏览 1 评论 0原文

我想从数组转换为 URL 的获取参数。 我知道apache的HTTPClient,但是它对于applet来说太大了。

有简单的解决方案吗?

我的小程序中有一个列表(或数组),我想为 HttpRequest 编写 URL 参数。 ParameterFormatter 很好,但是 jar 文件对于 applet 来说太大了。

编辑: 我发现有 Java Optimizer/Shrinker/Reducer 工具可以让你优化 jar。例如混淆者

I want to convert from array into get-parameters of URL.
I know HTTPClient of apache, but it's too large for applet.

is there simple solution?

I have a List(or array) in my applet, and I want to write URL-parameters for HttpRequest.
ParameterFormatter is good, but the jar file is too large for applet.

edit:
I found there is Java Optimizer/Shrinker/Reducer tool allows you to optimize jar. eg proguard

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杆小烟枪 2024-12-15 20:53:30

您可以简单地自己开发一个,因为您只需将它们连接到一个查询字符串。我正在对您想要的进行一些假设(例如每个变量的键以 var 开头),但这里是:

public String buildUrl(String baseUrl, String[] getVars) {

    String url = baseUrl + "?";
    // Builds: http://mydomain.com/app?

    for (int i = 0; i < getVars.length; i++) {

        url += "var" + i + "=" + getVars[i];
        // Builds the query string, ...app?var1=lol

        if (i < getVars.length - 1) {

            url += "&";
            // Adds the & after each var except for the last one
            // ...app?var1=lol&
        }

        // repeat for each var until done
        // ... app?var1=lol&var2=cat
    }

    return url;

}

当然您可以对代码进行其他简单的实现和优化。也可能有一些 Java 类已经执行此操作,但似乎您必须 自己构建或使用 Apache Commons 3rd party 库(我知道你不能)。

You could simply develop one yourself as you only need to join them together to a query string. I'm doing some assumptions on what you want (such as the key for each variable starts with var) but here goes:

public String buildUrl(String baseUrl, String[] getVars) {

    String url = baseUrl + "?";
    // Builds: http://mydomain.com/app?

    for (int i = 0; i < getVars.length; i++) {

        url += "var" + i + "=" + getVars[i];
        // Builds the query string, ...app?var1=lol

        if (i < getVars.length - 1) {

            url += "&";
            // Adds the & after each var except for the last one
            // ...app?var1=lol&
        }

        // repeat for each var until done
        // ... app?var1=lol&var2=cat
    }

    return url;

}

There are of course other naïve implementations and optimizations to the code that you can do. There also might be some Java class that does this already, but it seems that you have to build it on your own or use the Apache Commons 3rd party library (which I understand you can't).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文