protected HttpUriRequest prepareRequest( int method, String baseUri, String path, HttpEntity paramsEntity) { URI uri = null; HttpUriRequest request = null; try { StringBuffer sb = new StringBuffer(); if (method == GET) { sb.append(baseUri); sb.append(path); if (paramsEntity != null) { sb.append("?"); try { IOTricks.copyStreamToStringBuffer(paramsEntity.getContent(), sb); } catch (IllegalStateException e) { Log.e(TAG, "Error preparing url", e); return null; } catch (IOException e) { Log.e(TAG, "Error preparing url", e); return null; } } uri = new URI(sb.toString()); if (SimpleHttpClient.debug) Log.i(TAG, "GET " + uri.toString()); if (SimpleHttpClient.debug && paramsEntity != null) Log.i(TAG, "-- " + IOTricks.StreamToString(paramsEntity.getContent())); request = new HttpGet(uri); } else if (method == POST) { sb.append(baseUri); sb.append(path); uri = new URI(sb.toString()); if (SimpleHttpClient.debug) Log.i(TAG, "POST " + uri.toString()); if (SimpleHttpClient.debug && paramsEntity != null) try { Log.i(TAG, "-- " + IOTricks.StreamToString(paramsEntity.getContent())); } catch (Exception e) { } request = new HttpPost(uri); request.getParams().setBooleanParameter("http.protocol.expect-continue", false); if (paramsEntity != null) { request.addHeader(paramsEntity.getContentType()); ((HttpPost) request).setEntity(paramsEntity); } else { request.addHeader("Content-Type", "application/x-www-form-urlencoded"); } } else if (method == PUT) { sb.append(baseUri); sb.append(path); uri = new URI(sb.toString()); if (SimpleHttpClient.debug) Log.i(TAG, "PUT " + uri.toString()); if (SimpleHttpClient.debug && paramsEntity != null) Log.i(TAG, "-- " + IOTricks.StreamToString(paramsEntity.getContent())); request = new HttpPut(uri); request.addHeader("Content-Type", "application/x-www-form-urlencoded"); request.getParams().setBooleanParameter("http.protocol.expect-continue", false); if (paramsEntity != null) { request.addHeader(paramsEntity.getContentType()); ((HttpPut) request).setEntity(paramsEntity); } else { request.addHeader("Content-Type", "application/x-www-form-urlencoded"); } } else if (method == DELETE) { sb.append(baseUri); sb.append(path); if (paramsEntity != null) { sb.append("?"); try { IOTricks.copyStreamToStringBuffer(paramsEntity.getContent(), sb); } catch (IllegalStateException e) { Log.e(TAG, "Error preparing url", e); return null; } catch (IOException e) { Log.e(TAG, "Error preparing url", e); return null; } } uri = new URI(sb.toString()); if (SimpleHttpClient.debug) Log.i(TAG, "DELETE " + uri.toString()); if (SimpleHttpClient.debug && paramsEntity != null) Log.i(TAG, "-- " + IOTricks.StreamToString(paramsEntity.getContent())); request = new HttpDelete(uri); } request.addHeader("User-Agent", userAgent()); } catch (URISyntaxException e) { Log.e(TAG, "Invalid URI for " + baseUri + " / " + path + " ...", e); } catch (IllegalStateException e) { Log.e(TAG, "Illegal State for " + baseUri + " / " + path + " ...", e); } catch (IOException e) { Log.e(TAG, "IOException for " + baseUri + " / " + path + " ...", e); } return request; }