Created
August 21, 2016 17:39
-
-
Save TooLazyy/2dd40f546331e741bb2fafbb5340e934 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//хэдеры | |
public static final Map<String, String> OPTIONS_HEADERS = new HashMap<String, String> () {{ | |
put("Access-Control-Request-Headers","authorization, content-type, accept, origin"); | |
put("Origin", "http://demos.algorithmia.com"); | |
put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7"); | |
put("Referer", "http://demos.algorithmia.com/colorize-photos/"); | |
put("Access-Control-Request-Method", "POST"); | |
}}; | |
public static final Map<String, String> MAIN_HEADERS = new HashMap<String, String> () {{ | |
put("Content-Type","application/json"); | |
put("Authorization", "Simple simT5hbarHkJ0y24isRZs2Gcb0g1"); | |
put("Accept", "application/json, text/javascript"); | |
put("Referer", "http://demos.algorithmia.com/colorize-photos/"); | |
put("Host","api.algorithmia.com"); | |
put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7"); | |
put("Origin", "http://demos.algorithmia.com"); | |
}}; | |
private class Test extends AsyncTask<String, Void, String> { | |
@Override | |
protected String doInBackground(String... params) { | |
try { | |
URL url = new URL("https://api.algorithmia.com/v1/web/algo/algorithmiahq/ColorizationDemo/1.1.14"); | |
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | |
conn.setReadTimeout(10000 /* milliseconds */); | |
conn.setConnectTimeout(15000 /* milliseconds */); | |
conn.setRequestMethod("POST"); | |
for (Map.Entry entry: Constants.MAIN_HEADERS.entrySet()) { | |
conn.setRequestProperty(entry.getKey().toString(),entry.getValue().toString()); | |
} | |
conn.setDoInput(true); | |
conn.setDoOutput(true); | |
conn.setUseCaches(false); | |
byte[] outputInBytes = "{https://pp.vk.me/c627131/v627131845/10eee/pYJV2Cmw11c.jpg}".getBytes("UTF-8"); | |
OutputStream os = conn.getOutputStream(); | |
os.write( outputInBytes ); | |
os.close(); | |
String line; | |
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getErrorStream())); | |
while ((line = reader.readLine()) != null) { | |
Log.i("MINE", line); | |
} | |
return "a"; | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
return null; | |
} | |
} | |
@Override | |
protected void onPostExecute(String s) { | |
super.onPostExecute(s); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment