REST请求格式协商咨询:多指定场景下的格式优先级疑问
Great question about Alfresco Web Script content negotiation! Let's break this down clearly:
First, it's important to know that Alfresco's Web Scripts (the endpoints under /alfresco/service/) follow a clear priority order for content format negotiation:
- Highest priority: The
formatquery parameter in the URL. This overrides any other format specifications. - Middle priority: The file extension in the URL path (like
.json,.xml, etc.). - Lowest priority: The
AcceptHTTP request header.
Now let's apply this to your specific request:
curl -uadmin:admin -H "Accept: text/html" "http://localhost:8080/alfresco/service/hellouser.xml?format=json"
You've included three format-related elements here:
format=json(query parameter).xml(URL path extension)Accept: text/html(request header)
Since the format=json query parameter has the highest priority, the Alfresco service will ignore the .xml suffix and Accept: text/html header, and return JSON format—exactly what you're expecting.
As a quick way to confirm, you can add -v to your curl command to view the response headers; you'll see the Content-Type header set to application/json, confirming the response format.
内容的提问来源于stack exchange,提问作者Eugen Konkov

