home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
Development
Submit: code patches (MediaPortal/TV-Server/etc.)
Utils: DownLoadImage failed when PageRequest need Header "User-Agent"
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="morfius" data-source="post: 1098908" data-attributes="member: 116650"><p>I'm still not familiar with the peculiarities of the MediaPortal code. My apologies. And even less with GitHub. More apologies. I prefer to answer here</p><p></p><p></p><p>This entry point is not used anymore, so is more simple....delete it?</p><p></p><p></p><p>You are rigth. This question <em>stuck in my inkwell</em>. Fixed.</p><p></p><p></p><p>Thanks</p><p></p><p></p><p>This have been tested with bad results. I prefer to keep it that way, but read again <strong>c)</strong> from my initial solutions, at the start of this post. (a little joke)</p><p></p><p>At this time, the code is as follows</p><p>[CODE]</p><p> [Obsolete("This entry point is deprecated, please use DownLoadImage(string strURL, string strFile) instead")] </p><p> public static void DownLoadImage(string strURL, string strFile, System.Drawing.Imaging.ImageFormat imageFormat)</p><p> {</p><p> if ((string.IsNullOrEmpty(strURL)) || (string.IsNullOrEmpty(strFile)))</p><p> return;</p><p> DownLoadImage(strURL, strFile);</p><p> }</p><p></p><p> /// <summary></p><p> /// Download a remote image and save it locally.</p><p> /// UserAgent and Accept headers are set for correct request.</p><p> /// Error handling is not responsibility of this method and should be done by method caller as seen fit</p><p> /// see https://forum.team-mediaportal.com/posts/1096988 for more details</p><p> /// </summary></p><p> /// <param name="strURL">remote image to download</param></p><p> /// <param name="strFile">local image to save</param></p><p> public static void DownLoadImage(string strURL, string strFile)</p><p> {</p><p> if ((string.IsNullOrEmpty(strURL)) || (string.IsNullOrEmpty(strFile)))</p><p> {</p><p> return;</p><p> }</p><p> Uri uri = new Uri(strURL);</p><p> HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(uri);</p><p> wReq.Proxy.Credentials = CredentialCache.DefaultCredentials;</p><p></p><p> wReq.UserAgent = "Mozilla/8.0 (compatible; MSIE 9.0; Windows NT 6.1; .NET CLR 1.0.3705;)";</p><p> wReq.Accept = "*/*";</p><p> wReq.Timeout = 20000;</p><p></p><p> using (HttpWebResponse wr = (HttpWebResponse)wReq.GetResponse())</p><p> {</p><p> using (Stream br = wr.GetResponseStream())</p><p> {</p><p> using (FileStream fs = new FileStream(strFile, FileMode.OpenOrCreate, FileAccess.Write))</p><p> {</p><p> br.CopyTo(fs);</p><p> }</p><p> }</p><p> }</p><p> }</p><p>[/CODE]</p><p></p><p>This code it's just a drop in the ocean, and far from the complexity of developing a mobile driver to manage MediaPortal, but this procedure is used a lot of times.</p><p>My only intention is that, this method work efficiently and quickly (of course without errors)</p><p></p><p>Greetings from Spain!</p></blockquote><p></p>
[QUOTE="morfius, post: 1098908, member: 116650"] I'm still not familiar with the peculiarities of the MediaPortal code. My apologies. And even less with GitHub. More apologies. I prefer to answer here This entry point is not used anymore, so is more simple....delete it? You are rigth. This question [i]stuck in my inkwell[/i]. Fixed. Thanks This have been tested with bad results. I prefer to keep it that way, but read again [b]c)[/b] from my initial solutions, at the start of this post. (a little joke) At this time, the code is as follows [CODE] [Obsolete("This entry point is deprecated, please use DownLoadImage(string strURL, string strFile) instead")] public static void DownLoadImage(string strURL, string strFile, System.Drawing.Imaging.ImageFormat imageFormat) { if ((string.IsNullOrEmpty(strURL)) || (string.IsNullOrEmpty(strFile))) return; DownLoadImage(strURL, strFile); } /// <summary> /// Download a remote image and save it locally. /// UserAgent and Accept headers are set for correct request. /// Error handling is not responsibility of this method and should be done by method caller as seen fit /// see https://forum.team-mediaportal.com/posts/1096988 for more details /// </summary> /// <param name="strURL">remote image to download</param> /// <param name="strFile">local image to save</param> public static void DownLoadImage(string strURL, string strFile) { if ((string.IsNullOrEmpty(strURL)) || (string.IsNullOrEmpty(strFile))) { return; } Uri uri = new Uri(strURL); HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(uri); wReq.Proxy.Credentials = CredentialCache.DefaultCredentials; wReq.UserAgent = "Mozilla/8.0 (compatible; MSIE 9.0; Windows NT 6.1; .NET CLR 1.0.3705;)"; wReq.Accept = "*/*"; wReq.Timeout = 20000; using (HttpWebResponse wr = (HttpWebResponse)wReq.GetResponse()) { using (Stream br = wr.GetResponseStream()) { using (FileStream fs = new FileStream(strFile, FileMode.OpenOrCreate, FileAccess.Write)) { br.CopyTo(fs); } } } } [/CODE] This code it's just a drop in the ocean, and far from the complexity of developing a mobile driver to manage MediaPortal, but this procedure is used a lot of times. My only intention is that, this method work efficiently and quickly (of course without errors) Greetings from Spain! [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
Development
Submit: code patches (MediaPortal/TV-Server/etc.)
Utils: DownLoadImage failed when PageRequest need Header "User-Agent"
Contact us
RSS
Top
Bottom