Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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

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# HttpResponseMessagePostAsync不';t反应_C#_Asp.net_Xamarin_Async Await - Fatal编程技术网

C# HttpResponseMessagePostAsync不';t反应

C# HttpResponseMessagePostAsync不';t反应,c#,asp.net,xamarin,async-await,C#,Asp.net,Xamarin,Async Await,我使用client.PostAsync没有收到任何响应。 我创建了xamarin表单中的按钮。它应该向服务器发送一些句子(json)并返回关于它们的信息(同样是json)。 按钮代码: private async void button_Analyze_Clicked(object sender, EventArgs e) { Request req = new Request() { UserId = this.UserId,

我使用client.PostAsync没有收到任何响应。 我创建了xamarin表单中的按钮。它应该向服务器发送一些句子(json)并返回关于它们的信息(同样是json)。 按钮代码:

private async void button_Analyze_Clicked(object sender, EventArgs e)
    {
        Request req = new Request()
        {
            UserId = this.UserId,

            Language = Convert.ToString(picker_Language.SelectedItem) + ".",

            Text = Convert.ToString(editor1.Text)
        };
        string jsonStr = JsonConvert.SerializeObject(req);

        Dictionary<string, string> dict = new Dictionary<string, string>();
        dict.Add("s", jsonStr);

        FormUrlEncodedContent form = new FormUrlEncodedContent(dict);

        HttpResponseMessage response = await client.PostAsync(markTextUrl, form).ConfigureAwait(false);
        string result = await response.Content.ReadAsStringAsync();
        Answer answ = JsonConvert.DeserializeObject<Answer>(result);
        answersList.Add(answ);

        await DisplayAlert("", " ", "Ok");
    }

永远不要返回响应,它不会到达控制器功能。如果我等待此代码完成,我将获取System.OperationCanceledExeption:“操作已取消”

是否确定
MarkTexture
指向控制器代码运行的正确locahost URL和端口?是私有只读字符串MarkTexture=“”;尝试在MarkTexture前面加上前缀http://http:// 没有很好的帮助您
markTexture
没有端口,看起来您只是超时了
public string MarkText(string s) //работа с запросом из приложения
        {
            Request req = JsonConvert.DeserializeObject<Request>(s);


            if (req != null)
            {
                Models.Request request = new Models.Request()
                {
                    Text = req.Text,
                    Lang = req.Language,
                    UserId = int.Parse(req.UserId)
                };
                AnalyzeRequest(request);   

                Answer answ = new Answer()
                {
                    Language = req.Language,
                    Text = req.Text,
                    Sentences = db.Histories.Last().Text,
                    Labels = db.Histories.Last().Label   
                };

                return JsonConvert.SerializeObject(answ);
            }
            return null;
        }
HttpResponseMessage response = await client.PostAsync(markTextUrl, form).ConfigureAwait(false);