2015-12-10 40 views

回答

2

User-Agent的报头的内容可从ClientInfo类的agent属性:

// Client side 
getRequest().getClientInfo().setAgent("something"); 

// Server side 
String userAgent = getRequest().getClientInfo().getAgent(); 

这可在客户端侧进行设置,并得到在服务器端。

如果在使用Restlet发送请求时未指定任何内容。例如,对于这样的代码:

String url = "http://localhost:8182/contacts/"; 
ClientResource cr = new ClientResource(url); 
cr.get(); 

标题的内容如下:

Jetty/9.2.6.v20141205,Restlet-Framework/2.3.1 

在我的情况中,我使用的Restlet 2.3.1与码头扩展为客户端接口(至实际发送请求)。

如果设置在客户端上的值,如下所述:

String url = "http://localhost:8182/contacts/"; 
ClientResource cr = new ClientResource(url); 
cr.getClientInfo().setAgent("My user agent"); 
cr.get(); 

现在,您将获得服务器端的这个值:

Jetty/9.2.6.v20141205,My user agent 

希望它可以帮助你, 蒂埃里

相关问题