Get request works with curl but not with javascript - json

I am trying to access information through a GET request. My javascript code is getting a successful response, but with an empty JSON array. I am trying to debug using curl and Firefox. Here is where it gets strange.
Here is a successful request through the Firefox:
http://api.example.com/v4/layers/2178198/features?token=...&filter=time%253E1384889546
This returns a bunch of data. This also works in my javascript code.
Now I do exactly the same request with a slightly different resource:
http://api.example.com/v4/layers/2178199/features?token=...&filter=time%253E1384889546
And I get a success, but the JSON array returned is empty. I do this exact same request with curl (from the same machine):
curl http://api.example.com/v4/layers/2178199/features?token=...&filter=time%253E1384889546
and I get a JSON array full of data.
So I know that I can GET data from the server with javascript and Firefox. And I know that this resource is valid, because I can access it through CURL. Why oh why do I get no data when accessing through the browser? I am very confused.

Related

How to use a GET curl in postman?

I have this curl example:
curl -i -X GET -H "Content-Type:application/json" https://dev.ga.coach/intervention/:getworse/ -d '{"user_id": "012ab3", "section_id": "6"}'
When I run it through cygwin it's working properly! When I'm trying to import it in postman then it shows it as POST and I get the following response.
<h1>Not Found</h1>
<p>The requested URL /intervention/ was not found on this server.</p>
When I test https://dev.ga.coach/intervention/:getworse/ through web browser, this is what I see:
cURL allows you to include a payload on a GET request but the HTTP specification says:
A payload within a GET request message has no defined semantics;
sending a payload body on a GET request might cause some existing
implementations to reject the request.
When you try to make the same request with Postman, you are experiencing it "rejecting" the request. In this case, the rejection comes in the form of it converting to a POST request instead.
It would be appropriate to include a JSON payload on a POST request, but since it looks like you are trying to GET information you should move the data to the URL instead.
For example:
https://dev.ga.coach/intervention/012ab3/6/:getworse/
This will require you change your server-side code (which you, presumably, can do since you said I'm developing the rest-apis) to read the data from the new location.

cannot get document id using box view api

In my app, after get "https://dl.boxcloud.com/*" url and send it to the View API, I receive this error:
{
message: "JSON parse error - No JSON object could be decoded"
type: "error"
request_id: "3ef12abcaf7a4c5abab5fb0d3959255e"
}
you can use this chrome extension to recreate this error
https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo
I tried with the other rest clients and it work correctly. Except in my app and the extension above.
I tried with the other rest clients and it work correctly. Except in my app and the extension above.
If this is the case, it's likely that the client you're using isn't actually sending properly formatted JSON. One way to debug this would be to output the raw HTTP request the client is sending and ensuring that it's actually sending the JSON properly.

Post parameter to Rest API

I need to post a json data and it's parameter to REST API. I know there might be some issues when using json in cross domain, but I tried using mozilla addon "http requester" and using "php-curl" and getting result in a json format as {"success":false}.
Is there any way to inspect the REST API using json data? If so please provide me some example to pass a json data to a REST API using a parameter.
If you have curl installed, at the command line you can do:
curl -d "{\"success\": false}" http://path/to/api?param=value

Extra /**/ in facebook profile picture json

Im trying to retrieve the URL for a facebook users profile pic. The call returns the JSON I expect as per http://developers.facebook.com/docs/reference/api/using-pictures/#json with one problem - if I specify callback=profile I get a /**/ at the start of the line. Unfortunately this is causing the JSON parser (lift-json) I am using to throw an exception.
Is there a way to stop the /**/ being returned? It seems odd but I cant see any reason its happening and thus see no way to turn it off.
The problem I am facing is shown below using curl.
andrews-MacBook-Pro:~ doctorb$ curl "http://graph.facebook.com/582931709/picture?redirect=false&type=normal"
{"data":{"url":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-ash4\/274518_582931709_901337157_s.jpg","is_silhouette":false}}
andrews-MacBook-Pro:~ doctorb$ curl "http://graph.facebook.com/582931709/picture/redirect=false&type=normal&callback=profile"
/**/ profile({"data":{"url":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-ash4\/274518_582931709_901337157_s.jpg","is_silhouette":false}});
Your first request is for simple JSON and your second request is for a JSONP formatted response.
Facebook adds a comment at the beginning of their JSONP response to prevent a vulnerability called "JSONP hijacking" in the web browser. As any requests to graph.facebook.com will include Facebook cookies, the comment will prevent malicious websites from simply including the request in a script tag and surreptitiously acting on behalf of the authenticated user.
If you want to use the JSONP request, instead of the simple JSON request, you will need to strip out the comment at the beginning of the response before passing it along to your JavaScript parser.

Can't see JSON response in JMeter View Results Tree

I was wondering if someone could tell me why I can't see the json response from a request that is also of type json in the JMeter View Results Tree. I know that the response is there because I use a regular expression to extract data (I wrote the reg ex based on result returned in Firebug). So the data can be extracted from the json response it just doesn't display in View Result Tree. I can see the json response for another request for a different app I performance test with JMeter, but that particular request is an ajax request. not sure
Add a sample writer and display content here.
http://jmeter.apache.org/usermanual/component_reference.html#Simple_Data_Writer
You will see the issue
HI there any one who looks in this post for jmeter, you may be bit worried when you cant find answers in internet regarding how to log your response when you sent a request , here is the solution and simple as it is...
just add a line like below.
result.setResponseData("put any content here to be displayed as String.", "UTF-8");
and check your response will be cool as you done.