Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将曲目上载到soundcloud时(422)无法处理的实体)_C#_Asp.net Mvc_Soundcloud - Fatal编程技术网

C# 将曲目上载到soundcloud时(422)无法处理的实体)

C# 将曲目上载到soundcloud时(422)无法处理的实体),c#,asp.net-mvc,soundcloud,C#,Asp.net Mvc,Soundcloud,我想尝试将mp3文件上载到我的soundcloud帐户。我已经为这份工作写了这段代码 WebClient client = new WebClient(); string postData = "client_id=" + "xxxxx" + "&client_secret=" + "xxx"

我想尝试将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();
                        }
                    }

当我调试这个代码部分时。我在catch块中得到(422)个不可处理的实体错误。为什么我会犯这个错误?如何解决这个问题

查看Soundcloud文档:


422-“请求看起来不错,但一个或多个参数看起来有点不正常。可能是您发送了错误格式的数据(例如,我们需要字符串的数组)。”

我找不到的“不正常”在哪里。此答案中的代码是否有帮助?对不起,我不知道该建议什么。你试过联系soundcloud吗?