Example usage for org.apache.http.impl.auth BasicSchemeFactory newInstance

List of usage examples for org.apache.http.impl.auth BasicSchemeFactory newInstance

Introduction

In this page you can find the example usage for org.apache.http.impl.auth BasicSchemeFactory newInstance.

Prototype

public AuthScheme newInstance(final HttpParams params) 

Source Link

Usage

From source file:edu.syr.bytecast.githubcampfire.CampfirePost.java

public CampfirePostReply post(String message) {
    //see: http://stackoverflow.com/questions/2603691/android-httpclient-and-https
    try {/*from   w ww .j  av  a 2s  .c  o m*/
        String xml_message = "<message><type>TextMessage</type><body>" + message + "</body></message>";

        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

        BasicSchemeFactory factory = new BasicSchemeFactory();

        HttpParams params = new BasicHttpParams();
        params.setParameter("realm", "https://trifort.campfirenow.com/");

        SingleClientConnManager mgr = new SingleClientConnManager(params, schemeRegistry);
        DefaultHttpClient client = new DefaultHttpClient(mgr, params);
        String url = "https://trifort.campfirenow.com/room/" + m_room + "/speak.xml";
        HttpPost post = new HttpPost(url);
        post.setHeader("Content-type", "application/xml");

        AuthScheme scheme = factory.newInstance(params);
        Header header = scheme.authenticate(new UsernamePasswordCredentials(m_apiKey), post);

        HttpEntity entity = new StringEntity(xml_message);
        post.setEntity(entity);
        post.setHeader(header);
        HttpResponse response = client.execute(post);

        return new CampfirePostReply(response);
    } catch (Exception ex) {//post.setEntity;
        ex.printStackTrace();
        return null;
    }
}