Java NanoHTTPD-无法访问响应类
我之所以这么说是因为我想用NanoHTTPD处理POST请求。当我把它放到Android Studio的Java NanoHTTPD-无法访问响应类,java,android,nanohttpd,Java,Android,Nanohttpd,我之所以这么说是因为我想用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并没有提出快速修复建议
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.
}
公众响应服务(IHTTP会话){
映射文件=新的HashMap();
Method=session.getMethod();
if(Method.PUT.equals(Method)| Method.POST.equals(Method)){
试一试{
session.parseBody(文件);
}捕获(ioe异常ioe){
返回新的响应(Response.Status.INTERNAL_ERROR,MIME_明文,“服务器内部错误:IOException:”+ioe.getMessage());
}捕获(响应异常re){
返回新的响应(re.getStatus(),MIME_明文,re.getMessage());
}
}
//去拿柱子
String postBody=session.getQueryParameterString();
//或者您可以访问POST请求的参数
字符串后参数=session.getParms().get(“参数”);
返回新响应(postBody);//或后参数。
}
您可以使用:newFixedLengthResponse替换新响应,如:
newFixedLengthResponse(“Hello”)。您可以使用:newFixedLengthResponse替换新响应,如:
newFixedLengthResponse(“Hello”)。发布演示问题的最小代码。我们不会挖掘您的链接。@greenapps ChangedA编译时错误。是哪种说法造成的?为什么让我们猜猜看?@greenapps每次提到“Response”类时,都会突出显示每个“newresponse”。发布演示该问题的最少代码。我们不会挖掘您的链接。@greenapps ChangedA编译时错误。是哪种说法造成的?为什么让我们猜猜?@greenapps每次提到“Response”类时,都会突出显示每个“newresponse”。