Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.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# 我没有收到REST API(POST)内容类型FormUrlEncode的响应_C#_Xaml_Xamarin_Xamarin.forms_Httpclient - Fatal编程技术网

C# 我没有收到REST API(POST)内容类型FormUrlEncode的响应

C# 我没有收到REST API(POST)内容类型FormUrlEncode的响应,c#,xaml,xamarin,xamarin.forms,httpclient,C#,Xaml,Xamarin,Xamarin.forms,Httpclient,当我尝试《邮递员》时,效果很好,我得到了回应 我想提出一个要求。我没有得到任何回应,请查看我的代码,让我知道我哪里做错了 using (var client = new HttpClient()) { var content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string

当我尝试《邮递员》时,效果很好,我得到了回应

我想提出一个要求。我没有得到任何回应,请查看我的代码,让我知道我哪里做错了

  using (var client = new HttpClient())
            {

                var content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("client_id", "11223asda"),
                    new KeyValuePair<string, string>("client_secret", "1232asdasa"),
                    new KeyValuePair<string, string>("code", "authcode3"),
                    new KeyValuePair<string, string>("grant_type", "authorization_code"),
                    new KeyValuePair<string, string>("redirect_uri", "http://www.google.com/")

                });

                var uri = new Uri("https://sandbox-api.userdomain.com/v2/oauth2/token");


                // var content = new FormUrlEncodedContent(obj);

                //HttpResponseMessage response = null;

                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri);

                request.Content = content;

                HttpResponseMessage response = await client.SendAsync(request);

                Debug.WriteLine(response.StatusCode);
输出:


对于这类工作,我使用以下库:


希望有帮助

提供的代码看起来是正确的。您需要提供更多详细信息。包装代码的方法是如何调用的?提供一个可以帮助我们更好地了解您的实际问题的示例。您是否调试了代码并检查了响应中得到的值。StatusCode?看起来Debug.WriteLine没有写入调试窗口。在HttpResponseMessage之后,它没有进入response.statuscode@ChetanRanpariya行。在向GC发送自动启动的请求时,我没有收到任何响应。API可能需要时间响应。您是否在Debug.WriteLine行上放置了断点并等待它被命中?你的代码是否有异常?如果您有断点,也可以尝试在Catch块中设置断点。您的工作邮递员示例和代码示例使用不同的URL…dexcom和userdomain
var client = new TinyRestClient(new HttpClient(),"https://sandbox-api.userdomain.com/");

var response = await client.
                PostRequest("v2/oauth2/token").
                AddFormParameter("client_id", "France").
                AddFormParameter("client_secret", "Paris").
                AddFormParameter("grant_type", "Paris").
                AddFormParameter("redirect_uri", "Paris").
                ExecuteAsync<Response>();