Created
January 11, 2010 22:11
-
-
Save pdeschen/274657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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