Search code examples
http-headersmvvmcrosswebrequest

can not set restricted headers e.g. UserAgent in WebRequest for PCL


microsoft did not implement it, and will not do so according to this: https://connect.microsoft.com/VisualStudio/feedback/details/770104/cannot-set-useragent-of-a-httpwebrequest-in-portable-class-and-winrt-libraries But the web site I'm trying to get response from requires User-Agent header specified in the request, otherwise the response is wrong. I am limited to using portable class library (PCL), since I'm working on mvvmcross cross platform project. What is the best way to make such a web request?


Solution

  • As I was trying to point you to in my first comment, Dependency Injection is the best way to go about this. Here is a simple example from the MvvmCross documentation https://github.com/MvvmCross/MvvmCross/wiki/Service-Location-and-Inversion-of-Control#1-pcl-interface-with-platform-specific-implementation