【问题标题】:Can I use firebase to pass data from an Android app to ASP.NET (Web Forms) and vice versa?我可以使用 firebase 将数据从 Android 应用程序传递到 ASP.NET(Web 窗体),反之亦然?
【发布时间】:2018-03-23 16:28:50
【问题描述】:

我想知道我是否能够使用 Firebase 将数据从 Android 应用程序传递到 ASP.NET Web 应用程序(Web 窗体),反之亦然(Web 到 Android 应用程序)。

谢谢

【问题讨论】:

    标签: android asp.net asp.net-mvc firebase


    【解决方案1】:

    为什么不直接使用HttpURLConnection 从应用程序传递到表单?

    这样的事情会将 JSON 数据发布到您选择的 URL,然后读回任何响应。

            HttpURLConnection conn   = null;
            StringBuilder     result = new StringBuilder();
            JSONObject        jObj   = null;
    
            // request method is POST
            try {
    
                URL urlObj = new URL();
    
    
                conn = (HttpURLConnection) urlObj.openConnection();
                conn.setDoInput(true);
                conn.setDoOutput(true);
                conn.setUseCaches(false);
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Accept-Charset", "UTF-8");
                conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                conn.setRequestProperty("Accept", "application/json");
    
                conn.setFixedLengthStreamingMode(data.getBytes().length);
                conn.setReadTimeout(10000);
                conn.setConnectTimeout(15000);
                conn.connect();
    
                DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
                wr.writeBytes(data);
                wr.flush();
                wr.close();
    
                //Receive the response from the server
                InputStream    in     = new BufferedInputStream(conn.getInputStream());
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                String         line;
                while ((line = reader.readLine()) != null) {
                    result.append(line);
                }
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            finally {
                if (conn != null) {
                    conn.disconnect();
                }
            }
    

    【讨论】:

    • 它是某种 Web API 吗?如果是,那么我可以在不知道 WCF 的情况下学习 Web API
    猜你喜欢
    • 2017-06-18
    • 2017-08-04
    • 1970-01-01
    • 2023-03-21
    • 2016-10-11
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    相关资源
    最近更新 更多