기본 콘텐츠로 건너뛰기

글

Android, HttpURLConnection

*** implementation new Thread(new Runnable() { public void run() {     HashMap params = new HashMap();           params.put("param1", "1");     HttpURLConnection connection = null;           try {         URL url = new URL("http://xxxxx.com/api/xxxx");                    connection = (HttpURLConnection)url.openConnection();         connection.setRequestMethod("POST");         connection.setRequestProperty("Accept", "application/json");         connection = ConnectionManager.setParams(connection, params);             connection.connect();             Integer responseCode...

Android, InputStream to JSON

public static JSONObject getInputStreamToJSON (InputStream inputStream) throws Exception { BufferedReader streamReader = new BufferedReader( new InputStreamReader(inputStream , "UTF-8" )) ; StringBuilder responseStrBuilder = new StringBuilder() ; String inputStr ; while ((inputStr = streamReader.readLine()) != null ) responseStrBuilder.append(inputStr) ; JSONObject jsonObject = new JSONObject(responseStrBuilder.toString()) ; //returns the json object return jsonObject ; }

iOS, NSURLSession, NSURLConnection depracated

*** NSURLConnection -> NSURLSession https://qiita.com/akitaika_/items/2f4fca20a82cb6895329 *** NSURLResponse.expectedContentLength == -1 [ request setValue :@ "identity" forHTTPHeaderField :@ "Accept-Encoding" ]; https://stackoverflow.com/questions/23834151/nsurlconnection-expectedcontentlength-returns-1 *** NSURLConnection sendSynchronousRequest NSURLSession * session = [ NSURLSession sharedSession ]; [[ session dataTaskWithURL :[ NSURL URLWithString : londonWeatherUrl ] completionHandler :^( NSData * data , NSURLResponse * response , NSError * error ) { // handle response }] resume ]; https://stackoverflow.com/questions/32643207/ios9-sendsynchronousrequest-deprecated *** NSURLConnection(procedure method) -> NSURLSession (Blocked method)   https://tennmemo.blogspot.com/2018/11/objc-method-wait-block-finish.html