【问题标题】:What are the headers to set in the Rest API for the HTTP GET request在 Rest API 中为 HTTP GET 请求设置的标头是什么
【发布时间】:2018-11-15 18:17:18
【问题描述】:
@api_view(['GET'])
def gatewayentities_list(request,format=None):
    requestMeta = request.META
    if ('HTTP_AUTHORIZATION' not in requestMeta.keys()):
        return JSONResponse({"status": "UNAUTHORIZED"}, status=401)
    elif (requestMeta['HTTP_AUTHORIZATION'] is not None):
        headerParameters = requestMeta['HTTP_AUTHORIZATION'].split(" ")
        companyid_id = headerParameters[2]
        apikey = headerParameters[0]
        userId = headerParameters[3]
        try:
            applicationid = int(headerParameters[4])
        except IndexError:
            applicationid = 0

{'Transfer-Encoding': 'chunked', 'Vary': 'Cookie', 'Server': 'Apache/2.2.29 (Amazon)', 'Connection': 'close', 'Date': 'Wed, 06 2018 年 6 月 06:50:09 GMT', 'Content-Type': 'text/html; charset=UTF-8'}

Server Error (500)

任何帮助将不胜感激!

【问题讨论】:

  • 寻找 curl 命令来解决这个问题

标签: java python ajax django


【解决方案1】:

您收到的错误似乎与请求映射标头无关。

你的请求映射方法应该是这样的:

@RequestMapping(produces = "application/json", method = RequestMethod.GET, value = "data")
public @ResponseBody ResponseEntity<?> gatewayentities_list(@ModelAttribute ,BindingResult errors, HttpServletRequest request, HttpServletResponse response){
// your code.
}

【讨论】:

    猜你喜欢
    • 2014-08-23
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 2021-12-02
    • 2012-08-06
    • 2014-09-01
    • 1970-01-01
    相关资源
    最近更新 更多