forked from github/cordova-plugin-webserver
Updated README.md and NanoHTTPDServer
This commit is contained in:
@@ -13,8 +13,10 @@ import fi.iki.elonen.NanoHTTPD;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NanoHTTPDWebserver extends NanoHTTPD{
|
||||
@@ -26,6 +28,11 @@ public class NanoHTTPDWebserver extends NanoHTTPD{
|
||||
this.webserver = webserver;
|
||||
}
|
||||
|
||||
private String inputStreamToString(InputStream inputStream) {
|
||||
Scanner s = new Scanner(inputStream).useDelimiter("\\A");
|
||||
return s.hasNext() ? s.next() : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a request object
|
||||
*
|
||||
@@ -44,7 +51,7 @@ public class NanoHTTPDWebserver extends NanoHTTPD{
|
||||
private JSONObject createJSONRequest(String requestId, IHTTPSession session) throws JSONException {
|
||||
JSONObject jsonRequest = new JSONObject();
|
||||
jsonRequest.put("requestId", requestId);
|
||||
jsonRequest.put("body", session.getParameters());
|
||||
jsonRequest.put("body", this.inputStreamToString(session.getInputStream()));
|
||||
jsonRequest.put("headers", session.getHeaders());
|
||||
jsonRequest.put("method", session.getMethod());
|
||||
jsonRequest.put("path", session.getUri());
|
||||
|
||||
Reference in New Issue
Block a user