英文:
ServiceStack GET Request Expects Body Data
问题
我正在使用ServiceStack v6框架作为OAuth认证提供程序的API服务。
认证过程正常,但在请求API数据的GET请求过程中,为了获得预期的结果,我需要在“body”中设置一个空的JSON值(类似:{})。在不同情况下,我会得到框架生成的HTML输出,这不是我想要的。
在下面的屏幕截图中,所需的结果在Postman上以空的JSON值显示在“body”部分:
在下面的屏幕截图中,没有在“body”部分看到预期之外的结果:
如何在不在“body”部分包含任何值的情况下获得预期结果?
英文:
I'm using the ServiceStack v6 framework for an API service with the OAuth as the authenticator provider.
The authentication process works fine but after that when I'm requesting some data from the API through the GET request process then in order to get the expected results, I need to set in the "body" an empty JSON value (something like: {}). In different case, I'm getting an HTML output produced by the framework which is not what I need.
On the below screen, the needed results are coming on Postman with an empty JSON value on the body part
On the below screen, unexpected results are coming on Postman with no value on the body part.
How can I get the expected result without any value on the body part?
答案1
得分: 0
请包括您的请求和响应DTO定义,以帮助确定您的API预期接受和返回什么。
如果您希望服务器返回JSON响应,您需要通过将Accept: application/json
添加到您的HTTP请求来指示它。
否则,如果您通过JSON /api 路由调用API,那么会隐含地返回JSON响应,例如,如果您的请求DTO是GetLoginUser
,您可以通过/api/GetLoginUser
调用API。
英文:
Please include your Request & Response DTO definitions to help identify what your API is expected to accept and return.
If you want the server to return a JSON response you need to instruct it to by adding Accept: application/json
to your HTTP Request.
Otherwise a JSON response is implied if you call the API via the JSON /api Route, e.g. if your Request DTO is GetLoginUser
you can call the API via /api/GetLoginUser
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论