无法在Google计算引擎上发出HTTP请求

时间:2018-08-06 03:01:34

标签: java google-app-engine google-cloud-platform google-compute-engine

我有一个运行ubuntu 16.04 lts的VM实例,并运行tomcat docker容器来运行java项目,该项目使用http向其他服务器发送消息,我可以到达主机和其余服务,并且可以运行websockets,但是当我尝试发送时http没有任何反应,即使没有崩溃我也已经在本地对其进行了测试,我已经配置了外部IP地址146.xxx.xxx.106并分配给该实例,并允许防火墙80和8080。

 Gson gson = new Gson();
        MessageOverNetwork message = gson.fromJson(messageOverNetwork, MessageOverNetwork.class);
        String userToken = DataFetcher.getUserToken(message.getToPhoneNumber());
        Notify notify = new Notify(userToken,message);
        String write = gson.toJson(notify);
        URL url = new URL(API_URL_FCM);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setUseCaches(false);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Accept-Charset", "utf-8");
        connection.setRequestProperty("Authorization","key="+AUTH_KEY_FCM);
        connection.setRequestProperty("Content-Type","application/json; charset=utf-8");
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(connection.getOutputStream(),"utf-8");
        outputStreamWriter.write(write);
        outputStreamWriter.flush();
        connection.getInputStream();
    }
    catch (MalformedURLException e)
    {
        e.printStackTrace();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }

0 个答案:

没有答案