diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-08-20 21:44:51 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-08-20 21:44:51 +0200 |
commit | e33e5b0003614d27365c8b2f713ba2293b0c13d3 (patch) | |
tree | 8e90d994e306d9e4c08dca2d5b2aefb0c9983365 /OpenKeychain/src/main/java | |
parent | 45706e653466743dcfd5ac5bb150f5a7907d59f3 (diff) | |
download | open-keychain-e33e5b0003614d27365c8b2f713ba2293b0c13d3.tar.gz open-keychain-e33e5b0003614d27365c8b2f713ba2293b0c13d3.tar.bz2 open-keychain-e33e5b0003614d27365c8b2f713ba2293b0c13d3.zip |
Work on upload key
Diffstat (limited to 'OpenKeychain/src/main/java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java index f617be62a..e63fdeb6d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java @@ -24,8 +24,10 @@ import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.util.Log; -import java.io.DataOutputStream; +import java.io.BufferedWriter; import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; @@ -352,24 +354,32 @@ public class HkpKeyserver extends Keyserver { @Override public void add(String armoredKey) throws AddKeyException { try { - String query = getUrlPrefix() + mHost + ":" + mPort + "/pks/add"; + String request = "/pks/add"; String params; try { - params = "keytext=" + URLEncoder.encode(armoredKey, "utf8"); + params = "keytext=" + URLEncoder.encode(armoredKey, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new AddKeyException(); } - Log.d(Constants.TAG, "hkp keyserver add: " + query); - - HttpURLConnection connection = openConnection(new URL(query)); - connection.setRequestMethod("POST"); - connection.addRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - connection.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length)); - connection.setDoOutput(true); - DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); - wr.writeBytes(params); - wr.flush(); - wr.close(); + URL url = new URL(getUrlPrefix() + mHost + ":" + mPort + request); + + Log.d(Constants.TAG, "hkp keyserver add: " + url.toString()); + + HttpURLConnection conn = openConnection(url); + conn.setRequestMethod("POST"); + conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + conn.setRequestProperty("Content-Length", Integer.toString(params.getBytes().length)); + conn.setDoInput(true); + conn.setDoOutput(true); + + OutputStream os = conn.getOutputStream(); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); + writer.write(params); + writer.flush(); + writer.close(); + os.close(); + + conn.connect(); } catch (IOException e) { throw new AddKeyException(); } |