OCRCamera/src/com/conordevilly/ocr/ocrcamera/OCRRESTClient.java
public String send(String toSend){
		String ret = "";

		try {
			//Put the data into a JSON object
			JSONObject json = new JSONObject();
			json.put("fileData", toSend);

			//Make a connection
			URL url = new URL(address + "/api/ocr");
			URLConnection connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setRequestProperty("Content-Type", "application/json");
			connection.setConnectTimeout(5000);
			connection.setReadTimeout(5000);

			//Send the data
			OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
			out.write(json.toString());
			out.close();

			//Read the response
			BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			String line;
			while((line = in.readLine()) != null){
				ret += line;
			}
			in.close();
		} catch(Exception e) {
			Log.e("OCR", e.getMessage());
		}

		return ret;
	}
//Sends a string to the service
Sends a string to the service
Sends a string to the service
public String send(String toSend){
		String ret = "";
		try {
			JSONObject json = new JSONObject();
			json.put("fileData", toSend);
			URL url = new URL(address + "/api/ocr");
			URLConnection connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setRequestProperty("Content-Type", "application/json");
			connection.setConnectTimeout(5000);
			connection.setReadTimeout(5000);
			OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
			out.write(json.toString());
			out.close();
			BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			String line;
			while((line = in.readLine()) != null){
				ret += line;
			}
			in.close();
		} catch(Exception e) {
			Log.e("OCR", e.getMessage());
		}
		return ret;
	}
public String send ( String toSend ) { String ret = "" ; try { JSONObject json = new JSONObject ( ) ; json . put ( "fileData" , toSend ) ; URL url = new URL ( address + "/api/ocr" ) ; URLConnection connection = url . openConnection ( ) ; connection . setDoOutput ( true ) ; connection . setRequestProperty ( "Content-Type" , "application/json" ) ; connection . setConnectTimeout ( 5000 ) ; connection . setReadTimeout ( 5000 ) ; OutputStreamWriter out = new OutputStreamWriter ( connection . getOutputStream ( ) ) ; out . write ( json . toString ( ) ) ; out . close ( ) ; BufferedReader in = new BufferedReader ( new InputStreamReader ( connection . getInputStream ( ) ) ) ; String line ; while ( ( line = in . readLine ( ) ) != null ) { ret += line ; } in . close ( ) ; } catch ( Exception e ) { Log . e ( "OCR" , e . getMessage ( ) ) ; } return ret ; }
Sends a string to the service
Sends a string to the service
//Put the data into a JSON object //Make a connection //Send the data //Read the response