views:

26

answers:

2

I am new to Restlet development, trying to add headers to do a HTTP request. I tried the following code, but got "400 bad request, the 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);

I am using Restlet 2.0. Please help. any sample code would be great help. thanks in advance. KC

A: 

Try using

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

Altough there might be other problems as well (myCT content-type?). Never used ClientID and DeviceID header also... but I'm a PHP guy :)

Claudiu
the server requires all these 4 field included in the header. so clientID and DeviceID must be there, I think...
Ok, but you have a typo, it's not Centent-Type:, it's Content-Type, the second header.
Claudiu
+1  A: 

HTTP protocol has a list of allowed headers: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

ClientID and DeviceID don't seem to be allowed headers. If you want custom headers you should prefix them with "X-".

Peter Knego