Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final private static String AUTH_USER = "foo";
- final private static String AUTH_PASS = "bar";
- private void postStringMatcherRequest(String encodedOpenID, String msg)
- {
- HttpClient httpclient = new HttpClient();
- httpclient.getState().setCredentials(
- new AuthScope("rvooz.org", 80, AuthScope.ANY_REALM),
- new UsernamePasswordCredentials(AUTH_USER, AUTH_PASS)
- );
- String contextURL = prefs.getString(PreferenceNames.CONTEXT_URL)+"/"+encodedOpenID;
- PostMethod request = new PostMethod(contextURL);
- request.setDoAuthentication( true );
- String np = AUTH_USER+":"+AUTH_PASS;
- byte[] auth = Base64.encodeBase64(np.getBytes());
- request.setRequestHeader("HTTP_AUTHORIZATION", new String(auth));
- try
- {
- RequestEntity entity = new StringRequestEntity(msg, CONTENT_TYPE, CHAR_SET);
- request.setRequestEntity(entity);
- try
- {
- log.info("request: "+contextURL+"\n"+ msg);
- int status = httpclient.executeMethod(request);
- log.info("response: " + status+"\n"+request.getResponseBodyAsString());
- }
- catch (HttpException e)
- {
- log.info("HttpException:"+e);
- e.printStackTrace();
- }
- catch (IOException e)
- {
- log.info("IOException:"+e);
- e.printStackTrace();
- }
- finally
- {
- request.releaseConnection();
- }
- }
- catch (UnsupportedEncodingException e)
- {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment