1

我是 Restlet 开发的新手,尝试添加标头来执行 HTTP 请求。我尝试了以下代码,但得到“400 bad request, header is not valid”

String url = "http://xxxxx";
Client c = new Client(Protocol.HTTP);

Request request = new Request(Method.GET, url);
HashMap attributes = new HashMap();

attributes.put = ("DeviceID", "myDeviceID");
attributes.put = ("Centent-Type", "myCT");
attributes.put = ("User-Agent", "my user agent");
attributes.put = ("ClientID", "myCid");

request.setAttributes(attributes);
Response r =c.handle(request);

我正在使用 Restlet 2.0。请帮忙。任何示例代码都会有很大帮助。提前致谢。KC

4

2 回答 2

3

HTTP 协议有一个允许的标头列表:http ://en.wikipedia.org/wiki/List_of_HTTP_header_fields

ClientID 和 DeviceID 似乎不允许使用标头。如果你想要自定义标题,你应该在它们前面加上“X-”。

于 2010-10-22T19:36:27.437 回答
0

尝试使用

attributes.put = ("Content-Type", "myCT");

尽管可能还有其他问题(myCT 内容类型?)。也从未使用过 ClientID 和 DeviceID 标头...但我是 PHP 人 :)

于 2010-10-22T04:52:24.327 回答