Advertisement
Guest User

Untitled

a guest
May 28th, 2014
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. String url = "http://192.168.1.135:9999/register_with_certificate";
  2.  
  3.  
  4. String urlParameters = "cert="+cert_x509.toString();
  5. URL obj = new URL(url);
  6. HttpURLConnection con = (HttpURLConnection) obj.openConnection();
  7.  
  8. //add reuqest header
  9. con.setRequestMethod("POST");
  10.  
  11. con.setRequestProperty("Accept-Language"
  12. , "en-US,en;q=0.5");
  13.  
  14.  
  15.  
  16. // Send post request
  17. con.setDoOutput(true);
  18. con.setFollowRedirects(true);
  19. DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  20.  
  21.  
  22.  
  23. wr.writeBytes(urlParameters);
  24. wr.flush();
  25. wr.close();
  26. con.setFollowRedirects(true);
  27.  
  28. String c= params.get("cert");
  29.  
  30. try {
  31. CertificateFactory cf = CertificateFactory.getInstance("X.509");
  32. ByteArrayInputStream bis = new ByteArrayInputStream(c.getBytes());
  33.  
  34.  
  35. Certificate cer = cf.generateCertificate(bis);
  36. } catch (CertificateException e1) {
  37. // TODO Auto-generated catch block
  38.  
  39. System.out.println("catch-------------------");
  40. }
  41.  
  42. java.security.cert.CertificateException:Could not parse certificate: java.io.IOException: Empty input
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement