本文整理汇总了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);
}
示例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());
}
示例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)
//.........这里部分代码省略.........