【发布时间】:2016-12-18 02:34:21
【问题描述】:
我在 SO 上关注 this post,因为我想使用 NanoHTTPD 处理 POST 请求。当我将它放入 Android Studio 中的 MainActivity 类时,它给了我一个错误:
'Response(fi.iki.elonen.NanoHTTPD.Response.lStatus,java.lang.String,java.io.lnputStream, long)' 在 'fi.iki.elonen.NanoHTTPD.Response' 中具有受保护的访问权限
很遗憾,Android Studio 没有建议快速修复,那么我该如何解决呢?
我的代码:
public Response serve(IHTTPSession session) {
Map<String, String> files = new HashMap<String, String>();
Method method = session.getMethod();
if (Method.PUT.equals(method) || Method.POST.equals(method)) {
try {
session.parseBody(files);
} catch (IOException ioe) {
return new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
} catch (ResponseException re) {
return new Response(re.getStatus(), MIME_PLAINTEXT, re.getMessage());
}
}
// get the POST body
String postBody = session.getQueryParameterString();
// or you can access the POST request's parameters
String postParameter = session.getParms().get("parameter");
return new Response(postBody); // Or postParameter.
}
【问题讨论】:
-
发布演示问题的最小代码。我们不会挖掘您的链接。
-
@greenapps 已更改
-
编译时错误。哪个声明导致了它?为什么让我们猜?
-
@greenapps 每次提到“响应”类时,都会突出显示每个“新响应”。