Hi,
If I query the webservice with format=json, I expect the response to be in application/json. It is in text/plain. Is this correct?
Latest piwigo, php 5.6.40.
Regards,
Sridhar
Offline
Hi sridharb,
Replies are generally in JSON but it happens that they are in text/plain when the server encountered an error.
Offline
Type text/plain also without error.
Offline
Could you please give an example which leads to a text/plain message and which is not due to a server error?
Offline
Just try:
curl -sSi 'https://YOURGALLERY/ws.php?format=json&method=pwg.getVersion' | grep -E '^(Content-Type:|\{)'
Which is no wonder as include/ws_protocols/json_encoder.php has
function getContentType() { return 'text/plain'; }
Offline
I did not look into this detail beforehand and you are perfectly right. The content type should be application/json as described by RFC4627.
I have replaced 'text/plain' with 'application/json' in the file /include/ws_protocols/json_encoder.php and everything works fine with the iOS app awaiting for JSON data. However, web browsers have issues and loading the tools/ws.htm page returns an 'error when parsing JSON string'. So some work needs to be done to fix this issue before switching to 'application/json'.
Offline
Would also be good to test with known JSON consumers of the API, though I only know an XML consumer.
The failure with tools/ws.htm seems to be due to jQuery.parseJSON(json) in function parsePwgJSON(json), if that's inevitable then changing the content-type isn't such a good idea as jQuery is widespread.
Offline
I am writing a json consumer and that's why I reported this problem.
I, now, have to force the response to be read in json format even though it is in text/plain. Fortunately, my json parser has an override to do the same.
But it would be good if the API returns the correct content-type even in cases of error.
Offline