406 error thrown by RestAssured when expecting 404

117 views
Skip to first unread message

Shreejit Nair

unread,
Apr 11, 2018, 10:33:46 AM4/11/18
to REST assured
Hi,
On trying to setup headers in RestAssured:
Accept: text/plain
the server throws back a 406 error.

I have already set this up in the .headers(Map) that goes in as part of the RequestSpecification object. (similar to POSTMAN)
I believe that is all that needs to be done?

Do we need to take this value and set it up in the RequestSpecification.accept(ContentType.PLAINTEXT) or something?

This works correctly with curl and PostMan but does not work with RestAssured.
I am expecting the server to throw a 404 error but it keeps throwing a 406 (which causes me to believe something is incorrect with the accept header part)

Any suggestions?

Regards
Shreejit

Todd Bradley

unread,
Apr 11, 2018, 10:49:02 AM4/11/18
to rest-a...@googlegroups.com
When you use curl or Postman, what does the Accept header of the request get set to?

I don't totally understand your question, but yes, to set the Accept header in a request you'll use .accept(ContentType.TEXT). If you think your web service isn't handling Accept correctly, you can experiment by passing any string in, like .accept('not/legitimate').

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shreejit Nair

unread,
Apr 11, 2018, 11:35:45 AM4/11/18
to REST assured
Hi Todd,

This is exactly my issue. I am not setting the .accept(CONTENTTYPE.TEXT) anywhere.

The only thing I am doing is a:
requestObject.header('Accept','text/plain') // This is not enough I believe and that is where something is going wrong.

For example if you were using POSTMAN just setting the header to Accept : text/plain would have been enough
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.

Todd Bradley

unread,
Apr 11, 2018, 11:46:03 AM4/11/18
to rest-a...@googlegroups.com
Ah, I see. I can't remember how RA works if you set the Accept header using both the header method and the accept method. I would recommend just using the accept method. That's what I always do.

To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.

Shreejit Nair

unread,
Apr 11, 2018, 11:54:57 AM4/11/18
to REST assured
Thanks Todd.

I basically have a config file setup where folks can just dump in the request headers they want. The request spec builder is dynamically created on top of that.
That is a more natural flavor of setting up headers similar to POSTMAN.

Based on this information I would have to :
a. setup the .accept() method if there is an accept Header set by the user

I hope RA can support both but I am pretty clueless why RA has setup this additional mechanism, I thought the request headers in fact should be enough to determine the client server interaction.
Reply all
Reply to author
Forward
0 new messages