OSS回调成功了却显示203错误
ReOSS回调成功了却显示203错误
一、CallbackFailed Callback to application server failed, please check your callbackUrl
表明你的回调url在公网下不可访问
二、Response body is not valid json format
表面你回应oss的不是json格式的数据。注意文档中说oss会访问回调接口,把结果原样返回到用户前端,所以根据你自己的需要设定响应内容。
在sdk demo中是如下返回的(AppCallbackServer中):
protected void
doGet(HttpServletRequest request
, HttpServletResponse response)
throws ServletException
, IOException {
System.
out.println(
'用户输入url:' + request.getRequestURI())
;
response(request
, response
,
'input get '
,
200)
;}
private void
response(HttpServletRequest request
, HttpServletResponse response
, String results
, int status)
throws IOException {
String callbackFunName = request.getParameter(
'callback')
;
response.addHeader(
'Content-Length'
, String.
valueOf(results.length()))
;
if (callbackFunName ==
null || callbackFunName.equalsIgnoreCase(
''))
response.getWriter().println(results)
;
else
response.getWriter().println(callbackFunName +
'( ' + results +
' )')
;
response.setStatus(status)
;
response.flushBuffer()
;}
它直接返回一个inut get字符串,因此如果不改动的话返回的自然不是json格式。
只需要如下设置result就可以正常响应;
JSONObject object =
new JSONObject()
;object.put(
'code'
,
200)
;object.put(
'message'
,
'success')
;String results = JSONObject.
fromObject(object).toString()
;
this.response(request
, response
, results
,
200)
;
赞0
踩0