0

这是我用来验证 IAP 交易收据的代码。httpsURLConnection.getOutputStream() 抛出 SocketException:连接重置。缺少什么?

公共类 HttpsClient {

    public static void main(String[] args) {
        HttpURLConnection.setFollowRedirects(false);

        JSONObject jsonObject = new JSONObject();
        jsonObject
                .put("receipt-data",
                        "encodeReceipt");

        HttpURLConnection con = null;
        try {
            String url = "https://buy.itunes.apple.com/verifyReceipt";
            con = (HttpURLConnection) new URL(url).openConnection();

            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) con;
            httpsURLConnection.setDoOutput(true);

            OutputStreamWriter wr = null;
            wr = new OutputStreamWriter(httpsURLConnection.getOutputStream());
            wr.write(jsonObject.toString());
            wr.flush();

            // Get the response
            httpsURLConnection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(
                    httpsURLConnection.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                System.out.print(line);
            }
            rd.close();

            System.out.println(httpsURLConnection);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }
}
4

1 回答 1

-1

公司防火墙问题。整理好了!

于 2012-04-24T16:15:14.517 回答