I am trying to upload files from my app to SoundCloud. I have this working fine for Unity itself, but when i run it on my Android device it gets the following error:
System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result)
at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data)
Is this just not supported by Android or am i doing something wrong?
Below the code (I am using WebClient to get the SoundCloudToken, this works fine on Android)
System.Net.ServicePointManager.Expect100Continue = false;
var request = WebRequest.Create("https://api.soundcloud.com/tracks") as HttpWebRequest;
//some default headers
//file array
var files = new UploadFile[]
{
new UploadFile(file.FullName, "track[asset_data]", "application/octet-stream")
};
//other form data
var form = new System.Collections.Specialized.NameValueCollection();
form.Add("track[title]", "Some title");
form.Add("track[sharing]", "private");
form.Add("oauth_token", soundCloudToken);
form.Add("format", "json");
form.Add("Filename", "3.wav");
form.Add("Upload", "Submit Query");
try
{
using (var response = HttpUploadHelper.Upload(request, files, form))
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
var readString = reader.ReadToEnd();
}
}
}
catch (System.Exception ex)
{
Debug.Log (ex.ToString());
}
The code uses classes that i got from here:
http://aspnetupload.com/AspNetUploadSamples.zip
↧