本文整理汇总了C#中HttpClient.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.Execute方法的具体用法?C# HttpClient.Execute怎么用?C# HttpClient.Execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient.Execute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteRequest
protected internal virtual void ExecuteRequest(HttpClient httpClient, HttpRequestMessage
request)
{
object fullBody = null;
Exception error = null;
HttpResponse response = null;
try
{
Log.V(Log.TagSync, "%s: RemoteRequest executeRequest() called, url: %s", this, url
);
if (request.IsAborted())
{
Log.V(Log.TagSync, "%s: RemoteRequest has already been aborted", this);
RespondWithResult(fullBody, new Exception(string.Format("%s: Request %s has been aborted"
, this, request)), response);
return;
}
Log.V(Log.TagSync, "%s: RemoteRequest calling httpClient.execute", this);
response = httpClient.Execute(request);
Log.V(Log.TagSync, "%s: RemoteRequest called httpClient.execute", this);
// add in cookies to global store
try
{
if (httpClient is DefaultHttpClient)
{
DefaultHttpClient defaultHttpClient = (DefaultHttpClient)httpClient;
this.clientFactory.AddCookies(defaultHttpClient.GetCookieStore().GetCookies());
}
}
catch (Exception e)
{
Log.E(Log.TagRemoteRequest, "Unable to add in cookies to global store", e);
}
StatusLine status = response.GetStatusLine();
if (Utils.IsTransientError(status) && RetryRequest())
{
return;
}
if (status.GetStatusCode() >= 300)
{
Log.E(Log.TagRemoteRequest, "Got error status: %d for %s. Reason: %s", status.GetStatusCode
(), request, 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 (IOException e)
{
Log.E(Log.TagRemoteRequest, "io exception", e);
error = e;
// Treat all IOExceptions as transient, per:
// http://hc.apache.org/httpclient-3.x/exception-handling.html
Log.V(Log.TagSync, "%s: RemoteRequest calling retryRequest()", this);
if (RetryRequest())
{
return;
}
}
catch (Exception e)
{
Log.E(Log.TagRemoteRequest, "%s: executeRequest() Exception: ", e, this);
error = e;
}
Log.V(Log.TagSync, "%s: RemoteRequest calling respondWithResult. error: %s", this
, error);
RespondWithResult(fullBody, error, response);
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:90,代码来源:RemoteRequest.cs
示例2: ProcessMessage
public void ProcessMessage(string fbQueue)
{
AzureQueueStorage aqs = new AzureQueueStorage(azureAppName, string.Format("http://{0}.queue.core.windows.net", azureAppName), azureSharedKey, "SharedKey");
azureResults ar = aqs.Messages(cmdType.get, fbQueue, "", "", "");
string messageID = string.Empty;
string popReceipt = string.Empty;
string message = string.Empty;
while (ar.Succeeded)
{
if (ar.Body != null)
{
System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
xdoc.LoadXml(ar.Body);
System.Xml.XmlNodeList nodes = xdoc.SelectNodes("//QueueMessage");
if (nodes.Count != 0)
{
foreach (System.Xml.XmlNode node in nodes)
{
messageID = node.SelectSingleNode("MessageId").InnerText;
if (node.SelectNodes("//PopReceipt").Count > 0)
popReceipt = node.SelectSingleNode("PopReceipt").InnerText;
if (node.SelectNodes("//MessageText").Count > 0)
message = node.SelectSingleNode("MessageText").InnerText;
xdoc.LoadXml(message);
nodes = xdoc.SelectNodes("//fbGetUserInfo");
foreach (XmlNode n in nodes)
{
string fbUserID = n.Attributes["fbUserID"].Value;
Trace.WriteLine(string.Format("Processing fb information for user {0}", fbUserID), "Information");
string fbOAuthToken = n.Attributes["fbOAuthToken"].Value;
string fbauthExpires = n.Attributes["authExpires"].Value;
while (fbUserID.StartsWith("fb"))
fbUserID = fbUserID.Substring(2);
if (Convert.ToDateTime(fbauthExpires) > DateTime.UtcNow)
{
string graphURL = string.Format("https://graph.facebook.com/{0}/friends/?access_token={1}", fbUserID, fbOAuthToken);
try
{
HttpClient ht = new HttpClient();
string graphInfo = ht.Execute(graphURL, "GET");
graphInfo = "{\"?xml\": {\"@version\": \"1.0\",\"@standalone\": \"no\"},\"root\": {" + graphInfo.Substring(1);// +"}}";
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(graphInfo);
LoadFriendList("fb" + fbUserID, doc.InnerXml);
}
catch(Exception ex) {
Console.WriteLine(ex.ToString());
}
try
{
//System.Net.HttpWebRequest req = null;
//System.Net.HttpWebResponse resp = null;
HttpClient ht = new HttpClient();
graphURL = string.Format("https://graph.facebook.com/{0}/?access_token={1}", fbUserID, fbOAuthToken);
// ht = new HttpClient();
//req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(graphURL);
//req.Method = "GET";
string graphInfo = ht.Execute(graphURL, "GET");
graphInfo = "{\"?xml\": {\"@version\": \"1.0\",\"@standalone\": \"no\"},\"root\": {" + graphInfo.Substring(1);// +"}}";
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(graphInfo);
UpdateUserDataSocialInformation("fb" + fbUserID, doc.InnerXml);
}
catch(Exception ex) {
Console.WriteLine(ex.ToString());
}
}
ar = aqs.Messages(cmdType.delete, fbQueue, "", string.Format("popreceipt={0}", popReceipt), messageID);
}
ar = aqs.Messages(cmdType.get, fbQueue, "", "", "");
}
}
else break;
}
}
}
示例3: 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);
}
示例4: ExecuteRequest
protected internal override void ExecuteRequest(HttpClient httpClient, HttpRequestMessage
request)
{
object fullBody = null;
Exception error = null;
HttpResponse response = null;
try
{
if (request.IsAborted())
{
RespondWithResult(fullBody, new Exception(string.Format("%s: Request %s has been aborted"
, this, request)), response);
return;
}
response = httpClient.Execute(request);
try
{
// add in cookies to global store
if (httpClient is DefaultHttpClient)
{
DefaultHttpClient defaultHttpClient = (DefaultHttpClient)httpClient;
this.clientFactory.AddCookies(defaultHttpClient.GetCookieStore().GetCookies());
}
}
catch (Exception e)
{
Log.E(Log.TagRemoteRequest, "Unable to add in cookies to global store", e);
}
StatusLine status = response.GetStatusLine();
if (status.GetStatusCode() >= 300)
{
Log.E(Log.TagRemoteRequest, "Got error status: %d for %s. Reason: %s", status.GetStatusCode
(), request, 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, response);
}
finally
{
try
{
inputStream.Close();
}
catch (IOException)
{
}
}
}
else
{
if (entity != null)
{
try
{
inputStream = entity.GetContent();
fullBody = Manager.GetObjectMapper().ReadValue<object>(inputStream);
RespondWithResult(fullBody, error, response);
}
finally
{
try
{
inputStream.Close();
}
catch (IOException)
{
}
}
}
//.........这里部分代码省略.........
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:101,代码来源:RemoteMultipartDownloaderRequest.cs
示例5: 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)
//.........这里部分代码省略.........