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


C# HttpRequestMessage.ToString方法代码示例

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


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

示例1: ExecuteRequest

		protected internal virtual void ExecuteRequest(HttpClient httpClient, HttpRequestMessage
			 request)
		{
			object fullBody = null;
			Exception error = null;
			try
			{
				HttpResponse response = httpClient.Execute(request);
				// add in cookies to global store
				try
				{
					if (httpClient is DefaultHttpClient)
					{
						DefaultHttpClient defaultHttpClient = (DefaultHttpClient)httpClient;
						CouchbaseLiteHttpClientFactory.Instance.AddCookies(defaultHttpClient.GetCookieStore
							().GetCookies());
					}
				}
				catch (Exception e)
				{
					Log.E(Database.Tag, "Unable to add in cookies to global store", e);
				}
				StatusLine status = response.GetStatusLine();
				if (status.GetStatusCode() >= 300)
				{
					Log.E(Database.Tag, "Got error " + Sharpen.Extensions.ToString(status.GetStatusCode
						()));
					Log.E(Database.Tag, "Request was for: " + request.ToString());
					Log.E(Database.Tag, "Status reason: " + status.GetReasonPhrase());
					error = new HttpResponseException(status.GetStatusCode(), status.GetReasonPhrase(
						));
				}
				else
				{
					HttpEntity temp = response.GetEntity();
					if (temp != null)
					{
						InputStream stream = null;
						try
						{
							stream = temp.GetContent();
							fullBody = Manager.GetObjectMapper().ReadValue<object>(stream);
						}
						finally
						{
							try
							{
								stream.Close();
							}
							catch (IOException)
							{
							}
						}
					}
				}
			}
			catch (ClientProtocolException e)
			{
				Log.E(Database.Tag, "client protocol exception", e);
				error = e;
			}
			catch (IOException e)
			{
				Log.E(Database.Tag, "io exception", e);
				error = e;
			}
			RespondWithResult(fullBody, error);
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:68,代码来源:RemoteRequest.cs

示例2: ToString_DefaultAndNonDefaultInstance_DumpAllFields

        public void ToString_DefaultAndNonDefaultInstance_DumpAllFields()
        {
            var rm = new HttpRequestMessage();
            string expected = 
                    "Method: GET, RequestUri: '<null>', Version: " + 
                    _expectedRequestMessageVersion.ToString(2) + 
                    ", Content: <null>, Headers:\r\n{\r\n}";
            Assert.Equal(expected, rm.ToString());

            rm.Method = HttpMethod.Put;
            rm.RequestUri = new Uri("http://a.com/");
            rm.Version = new Version(1, 0);
            rm.Content = new StringContent("content");

            // Note that there is no Content-Length header: The reason is that the value for Content-Length header
            // doesn't get set by StringContent..ctor, but ony if someone actually accesses the ContentLength property.
            Assert.Equal(
                "Method: PUT, RequestUri: 'http://a.com/', Version: 1.0, Content: " + typeof(StringContent).ToString() + ", Headers:\r\n" +
                "{\r\n" +
                "  Content-Type: text/plain; charset=utf-8\r\n" +
                "}", rm.ToString());

            rm.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain", 0.2));
            rm.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml", 0.1));
            rm.Headers.Add("Custom-Request-Header", "value1");            
            rm.Content.Headers.Add("Custom-Content-Header", "value2");

            Assert.Equal(
                "Method: PUT, RequestUri: 'http://a.com/', Version: 1.0, Content: " + typeof(StringContent).ToString() + ", Headers:\r\n" +
                "{\r\n" +
                "  Accept: text/plain; q=0.2\r\n" +
                "  Accept: text/xml; q=0.1\r\n" +
                "  Custom-Request-Header: value1\r\n" +
                "  Content-Type: text/plain; charset=utf-8\r\n" +
                "  Custom-Content-Header: value2\r\n" +
                "}", rm.ToString());
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:37,代码来源:HttpRequestMessageTest.cs

示例3: ExecuteRequest

		protected internal override void ExecuteRequest(HttpClient httpClient, HttpRequestMessage
			 request)
		{
			object fullBody = null;
			Exception error = null;
			try
			{
				HttpResponse response = httpClient.Execute(request);
				try
				{
					// add in cookies to global store
					if (httpClient is DefaultHttpClient)
					{
						DefaultHttpClient defaultHttpClient = (DefaultHttpClient)httpClient;
						CouchbaseLiteHttpClientFactory.Instance.AddCookies(defaultHttpClient.GetCookieStore
							().GetCookies());
					}
				}
				catch (Exception e)
				{
					Log.E(Database.Tag, "Unable to add in cookies to global store", e);
				}
				StatusLine status = response.GetStatusLine();
				if (status.GetStatusCode() >= 300)
				{
					Log.E(Database.Tag, "Got error " + Sharpen.Extensions.ToString(status.GetStatusCode
						()));
					Log.E(Database.Tag, "Request was for: " + request.ToString());
					Log.E(Database.Tag, "Status reason: " + status.GetReasonPhrase());
					error = new HttpResponseException(status.GetStatusCode(), status.GetReasonPhrase(
						));
				}
				else
				{
					HttpEntity entity = response.GetEntity();
					Header contentTypeHeader = entity.GetContentType();
					InputStream inputStream = null;
					if (contentTypeHeader != null && contentTypeHeader.GetValue().Contains("multipart/related"
						))
					{
						try
						{
							MultipartDocumentReader reader = new MultipartDocumentReader(response, db);
							reader.SetContentType(contentTypeHeader.GetValue());
							inputStream = entity.GetContent();
							int bufLen = 1024;
							byte[] buffer = new byte[bufLen];
							int numBytesRead = 0;
							while ((numBytesRead = inputStream.Read(buffer)) != -1)
							{
								if (numBytesRead != bufLen)
								{
									byte[] bufferToAppend = Arrays.CopyOfRange(buffer, 0, numBytesRead);
									reader.AppendData(bufferToAppend);
								}
								else
								{
									reader.AppendData(buffer);
								}
							}
							reader.Finish();
							fullBody = reader.GetDocumentProperties();
							RespondWithResult(fullBody, error);
						}
						finally
						{
							try
							{
								inputStream.Close();
							}
							catch (IOException)
							{
							}
						}
					}
					else
					{
						if (entity != null)
						{
							try
							{
								inputStream = entity.GetContent();
								fullBody = Manager.GetObjectMapper().ReadValue<object>(inputStream);
								RespondWithResult(fullBody, error);
							}
							finally
							{
								try
								{
									inputStream.Close();
								}
								catch (IOException)
								{
								}
							}
						}
					}
				}
			}
			catch (ClientProtocolException e)
//.........这里部分代码省略.........
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:101,代码来源:RemoteMultipartDownloaderRequest.cs


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