Guest User

Untitled

a guest
Mar 12th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. final private static String AUTH_USER = "foo";
  2. final private static String AUTH_PASS = "bar";
  3. private void postStringMatcherRequest(String encodedOpenID, String msg)
  4. {
  5. HttpClient httpclient = new HttpClient();
  6. httpclient.getState().setCredentials(
  7. new AuthScope("rvooz.org", 80, AuthScope.ANY_REALM),
  8. new UsernamePasswordCredentials(AUTH_USER, AUTH_PASS)
  9. );
  10. String contextURL = prefs.getString(PreferenceNames.CONTEXT_URL)+"/"+encodedOpenID;
  11. PostMethod request = new PostMethod(contextURL);
  12. request.setDoAuthentication( true );
  13.  
  14. String np = AUTH_USER+":"+AUTH_PASS;
  15. byte[] auth = Base64.encodeBase64(np.getBytes());
  16. request.setRequestHeader("HTTP_AUTHORIZATION", new String(auth));
  17.  
  18. try
  19. {
  20. RequestEntity entity = new StringRequestEntity(msg, CONTENT_TYPE, CHAR_SET);
  21. request.setRequestEntity(entity);
  22. try
  23. {
  24. log.info("request: "+contextURL+"\n"+ msg);
  25. int status = httpclient.executeMethod(request);
  26. log.info("response: " + status+"\n"+request.getResponseBodyAsString());
  27. }
  28. catch (HttpException e)
  29. {
  30. log.info("HttpException:"+e);
  31. e.printStackTrace();
  32. }
  33. catch (IOException e)
  34. {
  35. log.info("IOException:"+e);
  36. e.printStackTrace();
  37. }
  38. finally
  39. {
  40. request.releaseConnection();
  41. }
  42. }
  43. catch (UnsupportedEncodingException e)
  44. {
  45. e.printStackTrace();
  46. }
  47. }
Add Comment
Please, Sign In to add comment