Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 另一个URL内的URL(作为路径)_Java_Rest_Url_Restlet - Fatal编程技术网

Java 另一个URL内的URL(作为路径)

Java 另一个URL内的URL(作为路径),java,rest,url,restlet,Java,Rest,Url,Restlet,我想在Restlet中使用以下类型的URL:http://url.com/http://www.anotherurl.com/path 因此,我希望获得http://www.anotherurl.com/path作为参数。 然而,它什么也不做 另外,如果我使用http://url.com/path,然后我会毫无问题地收到“路径”http://url.com/www.anotherurl.com给了我www.anotherurl.com。然而http://url.com/www.anotherur

我想在Restlet中使用以下类型的URL:
http://url.com/http://www.anotherurl.com/path
因此,我希望获得
http://www.anotherurl.com/path
作为参数。 然而,它什么也不做


另外,如果我使用
http://url.com/path
,然后我会毫无问题地收到“路径”<代码>http://url.com/www.anotherurl.com给了我
www.anotherurl.com
。然而
http://url.com/www.anotherurl.com/path
是404。

您需要正确编码参数特殊字符。使用可执行此操作。

您需要正确编码参数特殊字符。使用来完成此操作。

事实上,这里有两个部分

  • 使用
    参考
    类的URL构建:

    Reference ref = new Reference();
    ref.setScheme("http");
    ref.setHostDomain("localhost");
    ref.setHostPort(8182);
    ref.addSegment("test");
    ref.addSegment("http://test");
    
    ClientResource cr = new ClientResource(ref);
    cr.get();
    
  • 获取作为路径参数的值并对其进行解码。以下是应用程序类中的路由配置:

    public Restlet createInboundRoot() {
        Router router = new Router(getContext());
        router.attach("/test/{id}", MyServerResource.class);
        return router;
    }
    
    以及服务器资源中相应的代码:

    public class MyServerResource extends ServerResource {
        @Get
        public Representation get() {
            String id = getAttribute("id");
            // Prints http%3A%2F%2Ftest
            System.out.println("id = "+id);
            // Prints http://test
            System.out.println("id = "+Reference.decode(id));
            return new EmptyRepresentation();
        }
    }
    
希望它能帮助你,
蒂埃里

事实上,这里有两个部分

  • 使用
    参考
    类的URL构建:

    Reference ref = new Reference();
    ref.setScheme("http");
    ref.setHostDomain("localhost");
    ref.setHostPort(8182);
    ref.addSegment("test");
    ref.addSegment("http://test");
    
    ClientResource cr = new ClientResource(ref);
    cr.get();
    
  • 获取作为路径参数的值并对其进行解码。以下是应用程序类中的路由配置:

    public Restlet createInboundRoot() {
        Router router = new Router(getContext());
        router.attach("/test/{id}", MyServerResource.class);
        return router;
    }
    
    以及服务器资源中相应的代码:

    public class MyServerResource extends ServerResource {
        @Get
        public Representation get() {
            String id = getAttribute("id");
            // Prints http%3A%2F%2Ftest
            System.out.println("id = "+id);
            // Prints http://test
            System.out.println("id = "+Reference.decode(id));
            return new EmptyRepresentation();
        }
    }
    
希望它能帮助你,
Thierry

您是说服务器端还是客户端?如果是服务器端,我不明白我应该做什么,最重要的是为什么..客户端。在服务器上,您必须获取URL的路径部分,并使用URL解码器进行类似的解码。您是指服务器端还是客户端?如果是服务器端,我不明白我应该做什么,最重要的是为什么..客户端。在服务器上,您必须获取URL的路径部分,并使用URL解码器进行类似的解码。这并没有帮助,404错误。以下是日志(我在ApacheTomcat上运行):
Dec 022015 4:38:24 AM org.restlet.engine.log.LogFilter afterHandle信息:2015-12-02 04:38:24 127.0.0.1-127.0.0.1 8080获取/测试/http://www.com	-	404	439	0	20	http://localhost:8080	curl/7.35.0-
但没有http://works罚款:
id=www.com id=www.com Dec 02,2015年4:36:52 AM org.restlet.engine.log.LogFilter afterHandle信息:2015-12-02 04:36:52 127.0.0.1-127.0.0.1 8080 GET/test/www.com-204 0 89http://localhost:8080	curl/7.35.0-
Hi。我真的很惊讶,因为我使它与2.3.1版一起工作。我只是在github repo()中提交了我的项目,所以您可以尝试一下……这没有帮助,404错误。以下是日志(我在ApacheTomcat上运行):
Dec 022015 4:38:24 AM org.restlet.engine.log.LogFilter afterHandle信息:2015-12-02 04:38:24 127.0.0.1-127.0.0.1 8080获取/测试/http://www.com	-	404	439	0	20	http://localhost:8080	curl/7.35.0-
但没有http://works罚款:
id=www.com id=www.com Dec 02,2015年4:36:52 AM org.restlet.engine.log.LogFilter afterHandle信息:2015-12-02 04:36:52 127.0.0.1-127.0.0.1 8080 GET/test/www.com-204 0 89http://localhost:8080	curl/7.35.0-
Hi。我真的很惊讶,因为我使它与2.3.1版一起工作。我刚刚在github repo()中提交了我的项目,所以您可以尝试一下。。。