public static HttpResponse createPost(String server,String username,String password,String token,boolean learningOptOut,String content,String voice,String codec) throws Exception {
  String url=server;
  HttpClient httpClient=new DefaultHttpClient();
  List<BasicNameValuePair> params=new LinkedList<BasicNameValuePair>();
  params.add(new BasicNameValuePair("text",content));
  params.add(new BasicNameValuePair("voice",voice));
  params.add(new BasicNameValuePair("accept",codec));
  HttpGet httpGet=new HttpGet(url + "?" + URLEncodedUtils.format(params,"utf-8"));
  if (token != null) {
    Log.d(TAG,"using token based authentication");
    httpGet.setHeader("X-Watson-Authorization-Token",token);
  }
 else {
    Log.d(TAG,"using basic authentication");
    httpGet.setHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(username,password),"UTF-8",false));
  }
  if (learningOptOut) {
    Log.d(TAG,"setting X-Watson-Learning-OptOut");
    httpGet.setHeader("X-Watson-Learning-Opt-Out","true");
  }
  HttpResponse executed=httpClient.execute(httpGet);
  return executed;
}

public static HttpResponse createPost ( String server , String username , String password , String token , boolean learningOptOut , String content , String voice , String codec ) throws Exception { String url = server ; HttpClient httpClient = new DefaultHttpClient ( ) ; List < BasicNameValuePair > params = new LinkedList < BasicNameValuePair > ( ) ; params . add ( new BasicNameValuePair ( "text" , content ) ) ; params . add ( new BasicNameValuePair ( "voice" , voice ) ) ; params . add ( new BasicNameValuePair ( "accept" , codec ) ) ; HttpGet httpGet = new HttpGet ( url + "?" + URLEncodedUtils . format ( params , "utf-8" ) ) ; if ( token != null ) { Log . d ( TAG , "using token based authentication" ) ; httpGet . setHeader ( "X-Watson-Authorization-Token" , token ) ; } else { Log . d ( TAG , "using basic authentication" ) ; httpGet . setHeader ( BasicScheme . authenticate ( new UsernamePasswordCredentials ( username , password ) , "UTF-8" , false ) ) ; } if ( learningOptOut ) { Log . d ( TAG , "setting X-Watson-Learning-OptOut" ) ; httpGet . setHeader ( "X-Watson-Learning-Opt-Out" , "true" ) ; } HttpResponse executed = httpClient . execute ( httpGet ) ; return executed ; }
post text data to the server and get returned audio data
