java - 在 Rest API 中为 HTTP GET 请求设置的标头是什么
问题描述
@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; 字符集=UTF-8'}
Server Error (500)
任何帮助,将不胜感激!
解决方案
您收到的错误似乎与请求映射标头无关。
您的请求映射方法应类似于:
@RequestMapping(produces = "application/json", method = RequestMethod.GET, value = "data")
public @ResponseBody ResponseEntity<?> gatewayentities_list(@ModelAttribute ,BindingResult errors, HttpServletRequest request, HttpServletResponse response){
// your code.
}
推荐阅读
- prolog - 如何使用 Aleph 和 SWI-Prolog 输出理论?
- sql - Oracle CASE WHEN 短路返回表达式
- powershell - 使用 Powershell 替换文本文件中的路径
- karate - 空手道是否支持 .avro 文件作为输入请求?
- ubuntu - 无法在 Ubuntu 上更新 QGIS
- mapbox-gl-js - 在地图框中的圆圈悬停时显示弹出窗口
- xcode - Xcode中如何隐藏调用栈中的第三方调用
- c++ - 如何绑定 SOCI 查询的输出?
- kubernetes - 使用 operator-sdk 生成“oneOf”属性
- json - 使用 jq 处理大文件时提高性能