Custom User Agent for HttpClient?

前端 未结 3 2018
小蘑菇
小蘑菇 2021-01-03 19:37

can I set a custom User Agent for a HttpClient?

I need to view websites in their mobile form.

3条回答
  •  Happy的楠姐
    2021-01-03 20:15

    var client = new HttpClient();
    client.DefaultRequestHeaders.UserAgent.ParseAdd("MyAgent/1.0");
    

    There is also a TryParseAdd if you want to catch bad attempts at adding it and Add if you want to create the ProductInfoHeaderValue with a name and version number yourself.

提交回复
热议问题