Code example for HttpsURLConnection

Methods: getResponseCodesetRequestMethodgetOutputStreamsetDoOutputsetRequestProperty

2
		protected Long doInBackground(URL... urls) {
			Long result = 0L;
			try{ 
				URL url = new URL("https://arecibo.appygram.com/appygrams");
				HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
				conn.setDoOutput(true);
				conn.setRequestMethod("POST");
				conn.setRequestProperty("Content-Type", "application/json");
				String input = new Gson().toJson(params);
				Log.i("Appygram Example","Sending: "+input);
				OutputStream os = conn.getOutputStream();
				os.write(input.getBytes());
				os.flush();	
				os.close();
				result = (long) conn.getResponseCode();
				Log.i("Appygram Example","Appygram sent with result "+result);
			} catch (IOException x) {
				Log.e("Appygram Example","Error sending appygram", x);
			} 
			return result;
Stop searching for code, let great code find you!  Add Codota to your java IDE