将Android虚拟设备连接到IIS Express本地

时间:2017-05-05 07:57:47

标签: android iis-express

我发现许多教程允许外部用户连接到IIS Express但它们都没有工作......这就是我所拥有的: 我的文件applicationhost.config: enter image description here

我访问本地服务器的代码:

private final String SERVER = "http://<my-pc-ip>:51234/Example/exemple";

protected String doInBackground(String... strJson ) {
    URL url;
    String response = "";
    try {
        url = new URL(SERVER);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(15000);
        conn.setConnectTimeout(15000);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("Accept", "application/json");
        conn.setRequestMethod("POST");
        conn.setDoInput(true);
        conn.setDoOutput(true);

        OutputStream os = conn.getOutputStream();
        BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os, "UTF-8"));
        writer.write(strJson[0]);
        writer.flush();
        writer.close();
        os.close();
        int responseCode=conn.getResponseCode();

        if (responseCode == HttpsURLConnection.HTTP_OK) {
            String line;
            InputStream inputStream = new BufferedInputStream(conn.getInputStream());
            response = convertStreamToString(inputStream);
        }
        else {
            response="NO HTTP_OK : " + responseCode;
        }
        conn.disconnect();
    } catch (MalformedURLException e) {
        response = "malformedURL" + e.toString();
    } catch (ProtocolException e) {
        response = "Protocol" + e.toString();
    } catch (IOException e) {
        response = "IOException" + e.toString();
    } catch (Exception e) {
        e.printStackTrace();
        response = "Exception" + e.toString();
    }
    return response;
}

private String convertStreamToString(InputStream is) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line).append('\n');
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
}

当我连接时:http://:51234 /示例/示例 我得到:错误400 - 当我连接时:10.0.2.2我得到:连接超时 - 当我连接:localhost我得到:连接被拒绝

我尝试了命令行(在管理员中): netsh http add urlacl url=http://*:51234/ user=everyone 但我得到:Échec de la création du SDDL ; erreur : 1789 Paramètre incorrect.

我正在使用visual studio 2017运行服务器,我无法触摸服务器上的脚本。请各位帮助我,我很满意这个问题!

编辑:我成功地使用netsh http add urlacl url=http://*:51234/ user=everyone以“tout le monde”代替“所有人”

我在Windows防火墙中放置了一个入站规则来接受端口51234,但现在我有一个错误503 :(

编辑2 :我的错误503是因为我修改了错误的applicationhost.config。如果您有Visual Studio 2017 applicationhost.config在您的项目中。当我编辑好的那个时,它立即起作用。

0 个答案:

没有答案