Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package toServer;
- import android.os.AsyncTask;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.*;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- public class ConnectToServer extends AsyncTask<String, Void, Void>{
- @Override
- protected Void doInBackground(String ... strings){
- String link;
- link = strings[0] + strings[1];
- try {
- URL url = new URL(link);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.connect();
- InputStream is = conn.getInputStream();
- BufferedReader reader =
- new BufferedReader(new InputStreamReader(is, "UTF-8"));
- /*
- String inputLine;
- while ((inputLine = reader.readLine()) != null)
- System.out.println(inputLine);
- reader.close();
- */
- String in,out = null;
- while((in = reader.readLine()) != null)
- out += in + "\n";
- reader.close();
- JSONObject jsonObject = new JSONObject(out);
- }
- catch (MalformedURLException e){
- e.printStackTrace();
- }
- catch (IOException e){
- e.printStackTrace();
- }
- catch (JSONException e){
- e.printStackTrace();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement