简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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