这是我用来验证 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();
}
}
}