【问题标题】:Can't get GET HTTP using Node js无法使用 Node js 获取 GET HTTP
【发布时间】:2015-11-04 09:21:25
【问题描述】:

这很奇怪。

我正在使用我的 android 设备向 LAN 中的节点 js 服务器发送消息。

现在问题来了:当我发送 POST HTTP 时,它确实有效。但是当我发送 GET HTTP 时它不起作用,服务器甚至没有收到 get 请求。

这是我接收 get 的代码:

app.get('/auth/facebook', passport.authenticate('facebook'));

这是 android 中用于发送 GET 的代码:

 public class Background_confirmation extends AsyncTask<Void, Integer, String> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();

       // progressDialog = ProgressDialog.show(Confirmation.this, "Please wait...", "Retrieving data ...", true);

    }

    @Override
    protected String doInBackground(Void... params) {

        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet("http://localhost:8080/auth/facebook");
        // replace with your url

        HttpResponse response = null;
        try {
            response = client.execute(request);

            Log.d("Response of GET request", response.toString());
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



        return response.toString();
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);


            // progressDialog.setCancelable(true);
      //  }
    }

有人知道为什么会这样吗?

【问题讨论】:

    标签: java android node.js server http-get


    【解决方案1】:

    您正在尝试从 localhost(即您的 Android 设备)而不是您的服务器获取数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-05
      • 2020-10-06
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      • 2018-12-02
      • 2015-03-28
      相关资源
      最近更新 更多