Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot host a website #540

Closed
generic-matrix opened this issue Apr 29, 2019 · 1 comment
Closed

Cannot host a website #540

generic-matrix opened this issue Apr 29, 2019 · 1 comment

Comments

@generic-matrix
Copy link

Hello,
I am trying to host a website but there is a issue with the mime type.

here is the code :
We have the code in the www folder

package com.example.sample.photolab;


import android.os.Environment;
import android.util.Log;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;

import java.io.FileReader;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import fi.iki.elonen.NanoHTTPD;


public class HTTP_SERVER extends NanoHTTPD {


    public HTTP_SERVER(int port) {
        super(port);
    }

    public HTTP_SERVER(String hostname, int port) {
        super(hostname, port);
    }


    @Override
    public Response serve(IHTTPSession session) {
        //String msg = "<html><body><h1>Hello server</h1>\n";
        Map<String, String> parms = session.getParms();
        /*if (parms.get("username") == null) {
            msg += "<form action='?' method='get'>\n";
            msg += "<p>Your name: <input type='text' name='username'></p>\n";
            msg += "</form>\n";
        } else {
            msg += "<p>Hello, " + parms.get("username") + "!</p>";
        }*/

        return newChunkedResponse(Response.Status.OK,"text/html",new ByteArrayInputStream(web_page().getBytes(StandardCharsets.UTF_8)));
    }


    private String web_page(){


        String answer = "";
        try {
            // Open file from SD Card
            File root = Environment.getExternalStorageDirectory();
            FileReader index = new FileReader(root.getAbsolutePath() +
                    "/www/index.html");
            BufferedReader reader = new BufferedReader(index);
            String line = "";
            while ((line = reader.readLine()) != null) {
                answer += line;
            }
            reader.close();

        } catch(Exception ioe) {
            Log.e("Httpd", ioe.toString());
        }

        return answer;
    }




}

Screen Shot 2019-04-29 at 8 30 48 PM

This is a ### MIME type error but one thing i can see that the files are getting indexed.

Thanks

@generic-matrix
Copy link
Author

www.zip
here is the website code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant