简体   繁体   English

为什么 Xamarin.Android 中的 PostAsync 不起作用?

[英]Why PostAsync in Xamarin.Android doesn't work?

When I'm using PostAsync in .net framework project it logs me in, but when I'm trying to use the same code in xamarin project it doesn't get through and it's still on login page.当我在 .net 框架项目中使用 PostAsync 时,它让我登录,但是当我尝试在 xamarin 项目中使用相同的代码时,它没有通过,它仍然在登录页面上。

public async static void WebScrapeData(){
    Dictionary<string, string> data = new Dictionary<string, string>
    {
        {"login", "<login>"},
        {"password", "<password>"}
    };
    HttpClient client = new HttpClient();
    FormUrlEncodedContent content = new FormUrlEncodedContent(data);
    HttpResponseMessage task = await client.PostAsync("<url>", content);
    string responseTask = await task.Content.ReadAsStringAsync();
}

In <...> there's actual data在 <...> 中有实际数据

Okay fixed after half a month.好的,半个月后修复。 For anyone else searching this problem it's created by visual studio emulation and to fix this you do: Project>Properties>Android Option>Advance>Http Client Implementations>Change Android to Managed.对于搜索此问题的其他任何人,它是由 Visual Studio 仿真创建的,要解决此问题,您可以执行以下操作:项目>属性>Android 选项>高级>Http 客户端实现>将 Android 更改为托管。 That's it, the answer was that simple... Anyway thanks to anyone who tried to help me, even if I didn't respond to you I tried your solution.就是这样,答案就是这么简单......无论如何,感谢任何试图帮助我的人,即使我没有回应你,我也尝试了你的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM