@@ -0,0 +1,4240 @@
+package ntnu.stud.markul.crowdshelf;%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.io.OutputStreamWriter;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.HttpURLConnection.*;%0Aimport java.net.URL;%0Aimport java.net.URLEncoder;%0A%0A/**%0A * Created by Torstein on 01.09.2015.%0A */%0Apublic class NetworkHelper %7B%0A    public static void sendPostRequest(String jsonData) %7B%0A        try %7B%0A            // instantiate the URL object with the target URL of the resource to%0A            // request%0A            URL url = new URL(%22https://something.herokuapp.com%22);%0A%0A            // instantiate the HttpURLConnection with the URL object - A new%0A            // connection is opened every time by calling the openConnection%0A            // method of the protocol handler for this URL.%0A            // 1. This is the point where the connection is opened.%0A            HttpURLConnection connection = (HttpURLConnection) url.openConnection();%0A            // set connection output to true%0A            connection.setDoOutput(true);%0A            // instead of a GET, we're going to send using method=%22POST%22%0A            connection.setRequestMethod(%22POST%22);%0A            connection.setRequestProperty(%22Content-Type%22, %22application/json%22);%0A%0A            // instantiate OutputStreamWriter using the output stream, returned%0A            // from getOutputStream, that writes to this connection.%0A            // 2. This is the point where you'll know if the connection was%0A            // successfully established. If an I/O error occurs while creating%0A            // the output stream, you'll see an IOException.%0A            OutputStreamWriter writer = new OutputStreamWriter(%0A                    connection.getOutputStream());%0A%0A            // write data to the connection. This is data that you are sending to the server%0A            writer.write(%22message=%22 + jsonData);%0A%0A            // Closes this output stream and releases any system resources%0A            // associated with this stream. At this point, we've sent all the%0A            // data. Only the outputStream is closed at this point, not the%0A            // actual connection%0A            writer.close();%0A            // if there is a response code AND that response code is 200 OK, do%0A            // stuff in the first if block%0A            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) %7B%0A%0A%0A            %7D else %7B%0A                // Server returned HTTP error code.%0A            %7D%0A        %7D catch (java.net.MalformedURLException e) %7B%0A            // ...%0A        %7D catch (IOException e) %7B%0A            // ...%0A        %7D%0A    %7D%0A%0A    public static void sendGetRequest(String jsonData) %7B%0A        try %7B%0A            URL url = new URL(%22https://something.herokuapp.com%22);%0A%0A            HttpURLConnection connection = (HttpURLConnection) url.openConnection();%0A%0A            connection.setDoOutput(true);%0A            connection.setRequestMethod(%22GET%22);%0A            connection.setRequestProperty(%22Content-Type%22, %22application/json%22);%0A%0A            InputStreamReader reader = new InputStreamReader(%0A                    connection.getInputStream());%0A%0A%0A            // Closes this output stream and releases any system resources%0A            // associated with this stream. At this point, we've sent all the%0A            // data. Only the outputStream is closed at this point, not the%0A            // actual connection%0A%0A            // if there is a response code AND that response code is 200 OK, do%0A            // stuff in the first if block%0A            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) %7B%0A                BufferedReader in = new BufferedReader(%0A                        new InputStreamReader(connection.getInputStream()));%0A                String inputLine;%0A                StringBuffer response = new StringBuffer();%0A%0A                while ((inputLine = in.readLine()) != null) %7B%0A                    response.append(inputLine);%0A                %7D%0A            %7D else %7B%0A                // Server returned HTTP error code.%0A            %7D%0A            reader.close();%0A        %7D catch (java.net.MalformedURLException e) %7B%0A            // ...%0A        %7D catch (IOException e) %7B%0A            // ...%0A        %7D%0A    %7D%0A%0A    private static void printRequest() %7B%0A    %7D%0A%0A%7D%0A

Add NetworkHelper