阅读背景:

将曲目上传到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.

我想尝试将mp3文件上传到我的soundcloud帐户。我为这份工作编写了这段代码。

                        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;
                        try
                        {
                            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?

当我调试这个代码部分。我在catch块中得到(422)Unprocessable Entity错误。为什么我会收到此错误?怎么能解决这个问题?

1 个解决方案

#1


0  

Check the Soundcloud documentation:

检查Soundcloud文档:

https://developers.soundcloud.com/docs#errors

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)."

422 - “请求看起来不错,但是一个或多个参数看起来有些麻烦。你可能以错误的格式发送数据(例如我们期望字符串的数组)。”


分享到: