While uploading tracks to soundcloud(422) Unprocessable Entity)

I would like to try upload a mp3 file to my soundcloud account. I have written this code for this job.

                        WebClient client = new WebClient();
                        string postData = "client_id=" + "xxxxx"
                                        + "&client_secret=" + "xxx"
                                        + "&grant_type=password&username=" + "xxx" //your username
                                        + "&password=" + "xxx";//your password :)
                        string soundCloudTokenRes = "https://api.soundcloud.com/oauth2/token";
                        string tokenInfo = client.UploadString(soundCloudTokenRes, postData);
                        tokenInfo = tokenInfo.Remove(0, tokenInfo.IndexOf("token\":\"") + 8);
                        string token = tokenInfo.Remove(tokenInfo.IndexOf("\""));
                        System.Net.ServicePointManager.Expect100Continue = false;
                        var request = WebRequest.Create("https://api.soundcloud.com/tracks") as HttpWebRequest;
                        request.CookieContainer = new CookieContainer();
                        //some default headers
                        request.Accept = "*/*";
                        request.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
                        request.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
                        request.Headers.Add("Accept-Language", "en-US,en;q=0.8,ru;q=0.6");
                        //file array
                        var files = new UploadFile[] { new UploadFile(filePath, "@/" + filePath, "application/octet-stream") };
                        //other form data
                        var form = new NameValueCollection();
                        form.Add("track[title]", "biksad");
                        form.Add("track[sharing]", "public");
                        form.Add("oauth_token", token);
                        form.Add("format", "json");

                        form.Add("Filename", fileName);
                        form.Add("Upload", "Submit Query");
                        string lblInfo;
                            using (var response = HttpUploadHelper.Upload(request, files, form))
                                using (var reader = new StreamReader(response.GetResponseStream()))
                                    lblInfo = reader.ReadToEnd();
                        catch (Exception ex)
                            lblInfo = ex.ToString();

When I debug this code part. I get (422) Unprocessable Entity error in catch block. Why I get this error? How can solve this problem?


Check the Soundcloud documentation:


422 - "The request looks alright, but one or more of the parameters looks a little screwy. It's possible that you sent data in the wrong format (e.g. an array where we expected a string)."

Need Your Help

Scroll to item in listview in Silverlight 3

silverlight listbox scroll

I have a silverlight 3 app with a textbox on the main window and a childwindow that has a list of all the potential textbox values. When I open that childwindow I want it to scroll to the correct ...

Stored grid Option does not apply the specific styles


I am working on a feature where in the user could customize the grid (adding, grouping, sorting,aggregation etc) and then can save this as a template.