C # obtain the remote image. The authorization authentication of the form user name and password is required.
Using system; using system. collections. generic; using system. drawing; using system. io; using system. LINQ; using system. net; using system. text; using system. web; using system. web. ui; using system. web. UI. webcontrols; namespace web. app_code {public partial class getfleximage: system. web. UI. page {public static readonly log4net. ilog log = log4net. logmanager. getlogger (system. reflection. methodbase. getcurrentmethod (). declaringtype); protected void page_load (Object sender, eventargs e) {If (request ["IMG"] = NULL | string. isnullorempty (request ["IMG"]) {return;} Try {string url = (request ["IMG"]). replace ("%", "% 25"); httpwebrequest wrequest; httpwebresponse response = NULL; Uri uri = new uri (URL); credentialcache cc = new credentialcache (); CC. add (Uri, "Basic", new networkcredential ("epapi", "password"); wrequest = (httpwebrequest) httpwebrequest. create (URI); wrequest. credentials = cc; wrequest. preauthenticate = true; wrequest. method = "Post"; wrequest. allowwritestreambuffering = false; wrequest. sendchunked = false; wrequest. keepalive = true; wrequest. contentlength = 0; // wrequest. sendchunked = true; // wrequest. contentlength = 100000; wrequest. timeout = 30000; wrequest. headers. add ("Authorization", "Basic" + convert. tobase64string (New asciiencoding (). getbytes ("epapi: epapiadmin"); try {response = (httpwebresponse) wrequest. getresponse ();} catch (webexception ER) {response = (httpwebresponse) er. response;} bitmap myimage = new Bitmap (response. getresponsestream (); memorystream MS = new memorystream (); myimage. save (MS, system. drawing. imaging. imageformat. GIF); response. clearcontent (); response. contenttype = "image/GIF"; log. debug ("image loading:" + (request ["IMG"]); response. binarywrite (Ms. toarray ();} catch (exception ERR) {log. debug ("image loading exception:" + server. htmldecode (request ["IMG"]) + err. message );}}}}