当前位置: 首页>>代码示例>>C#>>正文


C# Uri.OpenConnection方法代码示例

本文整理汇总了C#中System.Uri.OpenConnection方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.OpenConnection方法的具体用法?C# Uri.OpenConnection怎么用?C# Uri.OpenConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Uri的用法示例。


在下文中一共展示了Uri.OpenConnection方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessUrl

		/// <exception cref="System.IO.IOException"/>
		private static void ProcessUrl(Uri url)
		{
			URLConnection con = url.OpenConnection();
			//        con.setConnectTimeout(connectTimeout);
			//        con.setReadTimeout(readTimeout);
			InputStream @in = con.GetInputStream();
			// Read metadata
			Com.Drew.Metadata.Metadata metadata;
			try
			{
				metadata = ImageMetadataReader.ReadMetadata(@in);
			}
			catch (ImageProcessingException e)
			{
				// this is an error in the Jpeg segment structure.  we're looking for bad handling of
				// metadata segments.  in this case, we didn't even get a segment.
				System.Console.Error.Printf("%s: %s [Error Extracting Metadata]\n\t%s%n", e.GetType().FullName, url, e.Message);
				return;
			}
			catch (Exception t)
			{
				// general, uncaught exception during processing of jpeg segments
				System.Console.Error.Printf("%s: %s [Error Extracting Metadata]%n", t.GetType().FullName, url);
				Sharpen.Runtime.PrintStackTrace(t, System.Console.Error);
				return;
			}
			if (metadata.HasErrors())
			{
				System.Console.Error.Println(url);
				foreach (Com.Drew.Metadata.Directory directory in metadata.GetDirectories())
				{
					if (!directory.HasErrors())
					{
						continue;
					}
					foreach (string error in directory.GetErrors())
					{
						System.Console.Error.Printf("\t[%s] %s%n", directory.GetName(), error);
					}
				}
			}
			// Iterate through all values
			foreach (Com.Drew.Metadata.Directory directory_1 in metadata.GetDirectories())
			{
				foreach (Tag tag in directory_1.GetTags())
				{
					string tagName = tag.GetTagName();
					string directoryName = directory_1.GetName();
					string description = tag.GetDescription();
					// truncate the description if it's too long
					if (description != null && description.Length > 1024)
					{
						description = Sharpen.Runtime.Substring(description, 0, 1024) + "...";
					}
					System.Console.Out.Printf("[%s] %s = %s%n", directoryName, tagName, description);
				}
			}
		}
开发者ID:renaud91,项目名称:n-metadata-extractor,代码行数:59,代码来源:ProcessUrlUtility.cs

示例2: SetAttachment

 /// <summary>
 /// Sets the attachment with the given name.
 /// </summary>
 /// <remarks>
 /// Sets the <see cref="Couchbase.Lite.Attachment"/> with the given name. 
 /// The <see cref="Couchbase.Lite.Attachment"/> data will be written to 
 /// the <see cref="Couchbase.Lite.Database"/> when the 
 /// <see cref="Couchbase.Lite.Revision"/> is saved.
 /// </remarks>
 /// <param name="name">The name of the <see cref="Couchbase.Lite.Attachment"/> to set.</param>
 /// <param name="contentType">The content-type of the <see cref="Couchbase.Lite.Attachment"/>.</param>
 /// <param name="contentUrl">The URL of the <see cref="Couchbase.Lite.Attachment"/> content.</param>
 public void SetAttachment(String name, String contentType, Uri contentUrl) {
     try
     {
         var inputStream = contentUrl.OpenConnection().GetInputStream();
         var length = inputStream.Length;
         var inputBytes = inputStream.ReadAllBytes();
         inputStream.Close();
         SetAttachment(name, contentType, inputBytes);
     }
     catch (IOException e)
     {
         Log.E(Database.Tag, "Error opening stream for url: " + contentUrl);
         throw new RuntimeException(e);
     }
 }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:27,代码来源:UnsavedRevision.cs

示例3: SetAttachment

        /// <summary>
        /// Sets the attachment with the given name.
        /// </summary>
        /// <remarks>
        /// Sets the <see cref="Couchbase.Lite.Attachment"/> with the given name. 
        /// The <see cref="Couchbase.Lite.Attachment"/> data will be written to 
        /// the <see cref="Couchbase.Lite.Database"/> when the 
        /// <see cref="Couchbase.Lite.Revision"/> is saved.
        /// </remarks>
        /// <param name="name">The name of the <see cref="Couchbase.Lite.Attachment"/> to set.</param>
        /// <param name="contentType">The content-type of the <see cref="Couchbase.Lite.Attachment"/>.</param>
        /// <param name="contentUrl">The URL of the <see cref="Couchbase.Lite.Attachment"/> content.</param>
        public void SetAttachment(String name, String contentType, Uri contentUrl) {
            try {
                byte[] inputBytes = null;
                using(var inputStream = contentUrl.OpenConnection().GetInputStream()) {
                    var length = inputStream.Length;
                    inputBytes = inputStream.ReadAllBytes();
                }

                SetAttachment(name, contentType, inputBytes);
            } catch (IOException e) {
                Log.E(Database.TAG, "Error opening stream for url: {0}", contentUrl);
                throw new Exception(String.Format("Error opening stream for url: {0}", contentUrl), e);
            }
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:26,代码来源:UnsavedRevision.cs

示例4: SendRequest

        internal virtual HttpURLConnection SendRequest(string method, string path, 
            IDictionary<string, string> headers, IDictionary<string, object> bodyObj)
        {
            try
            {
                var url = new Uri(new Uri((string)bodyObj["remote_url"]), path);
                var conn = url.OpenConnection();
                conn.SetDoOutput(true);
                conn.SetRequestMethod(method);
                if (headers != null)
                {
                    foreach (string header in headers.Keys)
                    {
                        conn.SetRequestProperty(header, headers[header]);
                    }
                }
                var allProperties = conn.GetRequestProperties();
                if (bodyObj != null)
                {
                    //conn.SetDoInput(true);
                    var bais = mapper.WriteValueAsBytes(bodyObj);
                    conn.SetRequestInputStream(bais);
                }
/*                var router = new Couchbase.Lite.Router.Router(manager, conn);
                router.Start();
*/              return conn;
            }
            catch (UriFormatException)
            {
                Assert.Fail();
            }
            catch (IOException)
            {
                Assert.Fail();
            }
            return null;
        }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:37,代码来源:LiteTestCase.cs

示例5: Open

		/// <exception cref="System.IO.IOException"></exception>
		private HttpURLConnection Open(string method, string bucket, string key, IDictionary
			<string, string> args)
		{
			StringBuilder urlstr = new StringBuilder();
			urlstr.Append("http://");
			urlstr.Append(bucket);
			urlstr.Append('.');
			urlstr.Append(DOMAIN);
			urlstr.Append('/');
			if (key.Length > 0)
			{
				HttpSupport.Encode(urlstr, key);
			}
			if (!args.IsEmpty())
			{
				Iterator<KeyValuePair<string, string>> i;
				urlstr.Append('?');
				i = args.EntrySet().Iterator();
				while (i.HasNext())
				{
					KeyValuePair<string, string> e = i.Next();
					urlstr.Append(e.Key);
					urlstr.Append('=');
					HttpSupport.Encode(urlstr, e.Value);
					if (i.HasNext())
					{
						urlstr.Append('&');
					}
				}
			}
			Uri url = new Uri(urlstr.ToString());
			Proxy proxy = HttpSupport.ProxyFor(proxySelector, url);
			HttpURLConnection c;
			c = (HttpURLConnection)url.OpenConnection(proxy);
			c.SetRequestMethod(method);
			c.SetRequestProperty("User-Agent", "jgit/1.0");
			c.SetRequestProperty("Date", HttpNow());
			return c;
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:40,代码来源:AmazonS3.cs

示例6: ReadUrl

		/// <exception cref="System.IO.IOException"></exception>
		private static string ReadUrl(string filePath, string charCoding, bool urlIsFile)
		{
			int chunkLength;
			Stream @is = null;
			try
			{
				if (!urlIsFile)
				{
					Uri urlObj = new Uri(filePath);
					URLConnection uc = urlObj.OpenConnection();
					@is = uc.GetInputStream();
					chunkLength = uc.GetContentLength();
					if (chunkLength <= 0)
					{
						chunkLength = 1024;
					}
					if (charCoding == null)
					{
						string type = uc.GetContentType();
						if (type != null)
						{
							charCoding = GetCharCodingFromType(type);
						}
					}
				}
				else
				{
					FilePath f = new FilePath(filePath);
					if (!f.Exists())
					{
						throw new FileNotFoundException("File not found: " + filePath);
					}
					else
					{
						if (!f.CanRead())
						{
							throw new IOException("Cannot read file: " + filePath);
						}
					}
					long length = f.Length();
					chunkLength = (int)length;
					if (chunkLength != length)
					{
						throw new IOException("Too big file size: " + length);
					}
					if (chunkLength == 0)
					{
						return string.Empty;
					}
					@is = new FileInputStream(f);
				}
				TextReader r;
				if (charCoding == null)
				{
					r = new StreamReader(@is);
				}
				else
				{
					r = new StreamReader(@is, charCoding);
				}
				return ReadReader(r, chunkLength);
			}
			finally
			{
				if (@is != null)
				{
					@is.Close();
				}
			}
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:71,代码来源:Global.cs

示例7: OpenUrlConnection

		/// <summary>
		/// Can be overridden in subclasses to customize the URL connection opening
		/// process.
		/// </summary>
		/// <remarks>
		/// Can be overridden in subclasses to customize the URL connection opening
		/// process. By default, just calls
		/// <see cref="System.Uri.OpenConnection()">System.Uri.OpenConnection()</see>
		/// .
		/// </remarks>
		/// <param name="url">the URL</param>
		/// <returns>a connection to the URL.</returns>
		/// <exception cref="System.IO.IOException">if an I/O error occurs.</exception>
		protected internal virtual URLConnection OpenUrlConnection(Uri url)
		{
			return url.OpenConnection();
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:17,代码来源:UrlModuleSourceProvider.cs


注:本文中的System.Uri.OpenConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。