This is my code.
<iron-ajax auto
id="requestRepos"
url="myurl"
params='{"mycommaseperatedparams"}'
handle-as="json"
on-response="handleResponse"></iron-ajax>
If i manually hit the url in the broswer, it works. But this one does't.
It's a GET request.
HTTP status code 406 means that the server cannot return a representation which conforms to the Accept- headers. From the specs:
The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.
For more answers see here: What is "406-Not Acceptable Response" in HTTP?
This is most likely the the Accept header set to application/json by the iron-ajax element. The browser (Chrome) on the other hand by default sends requests with
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Where the */* bit matches any content type.
To fix you would have to work on the server side to allow JSON responses. You could also try setting the header explicitly although I expect iron-ajax to override Accept header anyway
<iron-ajax headers='{"Accept": "*/*"}' handle-as="json"></iron-ajax>
Again, the */* is just an example. You probably need a more specific media type.
Related
I am trying to implement some client side caching via etags and last modified headers; however, ember-data doesn't seem to be using the etags for the ajax requests. I only get 200 responses and never a 304. I don't see any ETag header being sent with the request headers.
When I make the ajax request multiple times directly from the browser address bar, I'll get 304 not modified responses after the first request, so I know the server is sending things back correctly.
Is there a configuration I need to set up to make this happen?
This is a CORS request, but I think that I have and I have exposed the ETag header:
Access-Control-Expose-Headers: ETag
and the Etag header is sent back with the response.
Scenario: I've two post requests in jmeter one is used for token generation which has content type "application/x-www-form-urlencoded" and second is used for xyz operation by using that token has content type application/json, how can i perform this in jmeter?
For 1st request just make sure to choose POST value from the "Method" dropdown and make sure that Use multipart/form-data box is not ticked
JMeter will automatically send application/x-www-form-urlencoded request header for POST
For 2nd request add a HTTP Header Manager as a child and configure it to send the required Content-Type header
How does ASP.NET web Api interprets an empty/no accept header in the request?
will it by default take it as application/json, etc...?
Considering w3 specifications the web-servers can negotiate to each other based on these rules including allowing request method types(GET, POST, etc), content-type and etc. If you wana accept an additional header in your webserver you must define that variable in your webserver configurations, despite not defining this variable cause your webserver won't recieve requests containign that variable in the request header. Default content-type in http request is text/plain.
Hope this can help u bro. Regards.
All,
Every HTTP Request I make to my test REST Service is sent with the method set to GET. Tomcat rejects with a 405 - Unsupported Method. Doesn't matter what I change it to (POST, PUT, etc) Jmeter always sends a GET.
I set up the simplest possible test case by creating a Threadgroup with an HTTP Request Sampler and a View Results Tree. I send a JSON body to the REST Services which just echos back the request along with an ID. Works great with Google's REST Client UI.
Here is the result from the View Results Tree:
Response code: 405
Response message: Method Not Allowed
Response headers:
HTTP/1.1 405 Method Not Allowed
Server: Apache-Coyote/1.1
Allow: POST
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1045
Date: Fri, 18 Jul 2014 21:39:27 GMT
Here is the RequestMapping from my REST Service
#RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
Here are some screenshots from my results. I wonder why there are two URI's below the HTTP Request in the tree? Notice the POST request looks correct.
Since the right answer is not provided yet: It's the "Follow Redirects" Option that causes this behavoir under certain circumstances.
see http://www.sqaforums.com/showflat.php?Cat=0&Number=687068&Main=675937
Try to end the 'Path' value of HTTP Request with '/'. It has to remove the GET result in View Results Tree.
I had the same problem. I tried everything also I read this question and all answers before find the thing that worked for me.
Content-Type should be application/json. It can not be text/html.
Set that in HTTP Header Manager. I assume you have set authentication details correctly.
We need to have three things properly set.
Content type which will be application/json
set the endpoint correctly in the path ,which you can see in soup ui
Check the port number on which the api wil get run on [All this u can first check on soupui and then try running the same in jmeter
I am developing an API using CodeIgniter and the RestServer for CI (see below). I am also using the Firefox RestClient plugin to test the API.
What I am wondering is how to do the test post (what format).
Tried {"desc":"value"} but it did not work. The API is not "seeing" the incoming post fields.
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/
the post body doesn't need to have a specific format, but the most convenient is to encode the body in the same way web browsers encode form data, specifically Content-Type: application/x-www-form-urlencoded. In particular, the Host and Content-Length headers are not optional, and the Content-Type header is usually needed to tell the server how to interpret the body. A well formed POST request will look like:
POST /path/to/resource HTTP/1.0
Host: example.com:80
Content-Length: 21
Content-Type: application/x-www-form-urlencoded
key=value&key2=value2
It's still up to the server to recognize the content-type header and parse the body that way.
Note that the data is after all the headers, not as part of the request path (in the first line).
Optionally, you can use Proxy Library which i wrote for CI. With that, you can simulate any of possible call to your API(its works for popular REST API too), with more simple syntax instead using cURL...
// An example call to your API end point using POST, will be simply
$this->load->library('proxy');
$this->proxy->http('POST', 'http://somesite.com/api/users', array('username' => 'foo', 'password' => 'bar'));
You can define whatsoever HTTP header too (like API Key or whatever else).