如果HTTP头中没有可选参数“CHARSET=UTF-8”,如何发送RESTLET POST请求?

如果HTTP头中没有可选参数“CHARSET=UTF-8”,如何发送RESTLET POST请求?,utf-8,soapui,soap-client,restlet,Utf 8,Soapui,Soap Client,Restlet,如何在没有可选参数的情况下发送RESTLET POST请求;HTTP头中的字符集=UTF-8 当我在UNIX中使用WGET为我的服务尝试这个概念验证时,我可以指定可选的内容类型:。。。在HTTP标头中,如下所示: 将编码指定为UTF-8: 省略编码: 当我在RESTLET中做类似的事情时 Form form = new Form(); String accessToken = "Moroni123"; form.set("access_token", accessToken); 如果我这样

如何在没有可选参数的情况下发送RESTLET POST请求;HTTP头中的字符集=UTF-8

当我在UNIX中使用WGET为我的服务尝试这个概念验证时,我可以指定可选的内容类型:。。。在HTTP标头中,如下所示:

将编码指定为UTF-8: 省略编码: 当我在RESTLET中做类似的事情时

Form form = new Form();

String accessToken = "Moroni123";

form.set("access_token", accessToken);
如果我这样做是为了查看表示:

Representation rep = form.getWebRepresentation();
我使用rep.toString方法看到了这一点:

[application/x-www-form-urlencoded,UTF-8]
有没有办法让它看起来像这样?SoapUI在没有UTF-8的情况下发送它,我如何在RESTLET中做到这一点

[application/x-www-form-urlencoded]

事实上,这个提示对应于Restlet表示中的字符集。您只需使用表示法上的方法setCharacterSet将其设置为null,就不会再在标头内容类型中使用UTF-8。以下代码对此进行了描述:

Form form = new Form();
String accessToken = "Moroni123";
form.set("access_token", accessToken);

Representation repr = form.getWebRepresentation();
MediaType mediaType = repr.getMediaType();
// corresponds to application/x-www-form-urlencoded
CharacterSet characterSet = repr.getCharacterSet();
// corresponds to UTF-8

rep.setCharacterSet(null);

ClientResource cr = new ClientResource("http://...");
cr.post(repr);
我们将收到以下请求:

POST / HTTP/1.1
Date: Thu, 19 Feb 2015 15:58:06 GMT
Content-Type: application/x-www-form-urlencoded
Accept: */*
User-Agent: Restlet-Framework/2.3.0
Cache-Control: no-cache
Pragma: no-cache
Host: 127.0.0.1:8181
Connection: keep-alive
Content-Length: 22

access_token=Moroni123
如果没有此选项,则标题内容类型的内容为:

希望有帮助,
Thierry

你能给我你使用的Restlet版本吗?谢谢
Form form = new Form();
String accessToken = "Moroni123";
form.set("access_token", accessToken);

Representation repr = form.getWebRepresentation();
MediaType mediaType = repr.getMediaType();
// corresponds to application/x-www-form-urlencoded
CharacterSet characterSet = repr.getCharacterSet();
// corresponds to UTF-8

rep.setCharacterSet(null);

ClientResource cr = new ClientResource("http://...");
cr.post(repr);
POST / HTTP/1.1
Date: Thu, 19 Feb 2015 15:58:06 GMT
Content-Type: application/x-www-form-urlencoded
Accept: */*
User-Agent: Restlet-Framework/2.3.0
Cache-Control: no-cache
Pragma: no-cache
Host: 127.0.0.1:8181
Connection: keep-alive
Content-Length: 22

access_token=Moroni123
Content-Type: application/x-www-form-urlencoded; charset=UTF-8