Skip to content

Instantly share code, notes, and snippets.

@pdeschen
Created January 11, 2010 22:11
Show Gist options
  • Save pdeschen/274657 to your computer and use it in GitHub Desktop.
Save pdeschen/274657 to your computer and use it in GitHub Desktop.
...
if (mBaseUrl.getProtocol().equals("https"))
{
UsernamePasswordCredentials credentials =
new UsernamePasswordCredentials(mAuthenticationUsername,
mAuthenticationPassword);
mHttpClient.getState().setCredentials(AuthScope.ANY, credentials);
mHttpClient.getParams().setAuthenticationPreemptive(true);
}
String composedUrl = mBaseUrl + "/" + relativePath;
PostMethod post = new PostMethod(composedUrl);
boolean success = false;
try
{
//new StringPart("Accept", "application/json"),
Part[] parts = {new FilePart("sound", source)};
post.setDoAuthentication(true);
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
int status = mHttpClient.executeMethod(null, post, mHttpClient.getState());
if (status == HttpURLConnection.HTTP_OK)
{
success = true;
}
else
{
throw new CacheException("Can't post content stream.
Error code: [" + status + "]");
}
}
catch (Exception exception)
{
throw new CacheException("Can't post content stream", exception);
}
finally
{
post.releaseConnection();
}
return success;
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment