Can I do the same with android Java basciacally I need to make a HttpURLConnection from android to the Theta camera. It is working when theta is connected via Access Mode and not working when its in client mode basically we are getting java.io.FileNotFoundException
JSONObject input = new JSONObject();
InputStream is = null;
try {
input.put("name", "camera.getLivePreview");
final URL url = new URL("http://192.168.18.47/osc/commands/execute");
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("THETAYLXXXXXXXX", "XXXXXXXX".toCharArray());
}
});
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty( "X-XSRF-Protected", "1" );
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.connect();
OutputStream os = connection.getOutputStream();
os.write(input.toString().getBytes());
is = connection.getInputStream();
final byte[] buffer = new byte[8196];
int readCount;
final StringBuilder builder = new StringBuilder();
while ((readCount = is.read(buffer)) > -1) {
builder.append(new String(buffer, 0, readCount));
}
final String response = builder.toString();
}
catch (IOException e) {
e.printStackTrace();
}