JSONP cross-domain request error - json

Is there a way to get response status when doing JSONP request. I mean, can I see if it was a successful request 200 OK, or not found 404, or not available, etc. ?
ALTERNATIVELY: Maybe there is a way to try to load .js file using new Image() object, i.e. assuming it is an image and then see the response status? Or try to load even something completely different?
Is there any JavaScript cross-domain way to check if a resource is available or 404 unavailable?

May be that library can be helpful:
https://github.com/jaubourg/jquery-jsonp

Related

Derivative Service 400 Bad Request

Sometimes when accessing the Forge Derivative Service API via
GET https://developer.api.autodesk.com/derivativeservice/v2/manifest/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6c3RlbW4vNTcwMzBkMzBjNzFkZWVmNDBkNjViNDAxLTBCOTlVamtJMXBnN2FkbE16UzJKSExVbzNjV3MtMEI5OVVqa0kxcGc3YWRHOTJlbVJtTnpablJ6TnhRV2N5V1hOT05qZEdPV2xwYVhoclBRLXVuZGVmaW5lZC5kd2c
I get the response
<HTML><HEAD>
<TITLE>Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
Your browser sent a request that this server could not understand.<P>
Reference #7.425832b8.1500624784.0
</BODY>
</HTML>
How can I find out what it was about my request that the server did not understand. This is a simple GET request so I'm not sure what I am doing so that my request is not understood.
First, there is no endpoint like you are describing (see list): derivativeservice/v2/manifest/:urn doesn't exist, aren't you missing something? Which endpoint are you trying to call? Maybe manifest?
Second, when I base64 DECODE your URN, I'm getting:
urn:adsk.objects:os.object:stemn/57030d30c71deef40d65b401-0B99UjkI1pg7adlMzS2JHLUo3cWs-0B99UjkI1pg7adG92emRmNzZnRzNxQWcyWXNONjdGOWlpaXhrPQ-undefined.dwg
This undefined at the end is a bit suspicious and may be causing this problem. Can you double check the URN before encoding it? If that's a file on a bucket, seems incomplete/incorrect anyway.

API Request Redirect with Response

Say for example I'm try to make a GET Request to www.testjson.com/json, However the response is retrieved from a different domain URL e.g. www.testjson.com/confirmJson.
Does Spring mvc support this, specifically restTemplate.exchange functionality.
I am currently doing this sort of thing, but I am getting an 500 status code (internal server error) and have no way of finding out what exactly is causing the error.
So can RestTemplate actually manage the redirect and provide the necessary JSON response or does it actually wait for the response from the url you provide hence the reason for getting the 500 internal server error?
It is possible to let a RestTemplate automatically follow a redirect.
The server must respond with a Http 3xx and the location header set.
The RestTemplate 'understands' this response and issues a new GET request to the returned location.
This should work with default spring configuration.
See also follow-302-redirect-using-spring-resttemplate

Best practice for 404 page for API

I am writting REST API now. I faced with one problem - how 404 page in api should look like.
Of course it will be better to show user link to the API documentation.
But what about page in general.
Should it be beautiful page or just simple text also in JSON or XML format.
If page has a lot of images/scripts, we have to use network connection inefficiently.
Surely, we can get only headers of http response but it seems to be bad solution.
I have looked on several well-known APIs and the way how do they implement 404 pages.
Both Flickr and Twitter has 404 pages with some images, css.
But Github has pretty simple response, just JSON with following content.
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
I think this is good example of response (without images and css) if not please correct me.
So my question is what is the best practice for the 404 API response, should it be pretty simple (like on GitHub) or it is better to add some other useful information about API.
Thanks everyone in advance.
If someone request an API they will most likely catch the 404 exception and look for the HttpStatusCode. If it's 404 they don't need more information and just report that the User (?) is not found.
So it doesn't really matter what you do as 99% of the request won't even download the response site
A 404 Not Found response in an API is not required to have any content at all. The client code will probably look at the status code before it looks at the content of the request.
Every REST client code I've written so far does not concern itself with the body of a 404 Not Found response. I can not imagine anything in the body that has any use above the fact that the resource was not found.

qooxdoo json/request transport method

I try to send a request to my server via GET, but qooxdoo sends request as OPTIONS. Is any way to change this behaviour?
I try to use qx.data.store.Json (url) and qx.io.remote.Request (url, "GET", type) but result is same in both cases.
My version of qooxdoo is 1.0.1, browsers are FF 3.5.6 and Chromium 5.0.361.
It is most likely a problem due to cross browser restrictions. Give the JSONP store a try and deliver your data as JSONP to get rid of that problem.
I think this is because I try to send cross-domain request from file:/// to http://.
If I deploy a test application to server - it works fine.

WinINet: How to prevent HttpSendRequest to follow redirects (30x Status Codes)?

When I make an HTTP request with the method HttpSendRequest of the WinINet API, and the response sends "302: Moved Temporarily", the WinINet API automatically follows the redirection instruction and makes a new request.
So, How to prevent HttpSendRequest to follow redirects (30x Status Codes)?
I don't want't to make two requests... I wan't to get the the first response it got with the status code 302 in it's header.
I found a flag INTERNET_FLAG_NO_AUTO_REDIRECT that I must pass to HttpOpenRequest.
But, it isn't working....
Redirection can be prevented if you are able to use WinHTTP instead (link).
Try using INTERNET_FLAG_NO_AUTO_REDIRECT in the call to HttpSendRequest. Sounds like you're trying to use it from HttpOpenRequest.
I use this flag with InternetOpenUrl, and it works properly in that call.
Seems like WinInet behavior largely depends of lpszAgent specified in the InternetOpen function call. When you pass "Mozilla/5.0 (compatible)" all redirects are ignored and you will get RAW HTML result when reading response with InternetReadFile.
On the other hand, if you need "redirected" output, you must specify your application name in the Agent argument, for example "ConEmu Update".