本文整理汇总了C#中IRestResponse类的典型用法代码示例。如果您正苦于以下问题:C# IRestResponse类的具体用法?C# IRestResponse怎么用?C# IRestResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IRestResponse类属于命名空间,在下文中一共展示了IRestResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDefaultResponse
private static HttpServerResponse GetDefaultResponse(IRestResponse response)
{
var serverResponse = HttpServerResponse.Create(response.StatusCode);
serverResponse.Date = DateTime.Now;
serverResponse.IsConnectionClosed = true;
return serverResponse;
}
示例2: DownloadAllFilesLocal
static void DownloadAllFilesLocal(Dictionary<string, string> downloadList, string chosenFilePath, string chosenFolderName, IRestResponse loginResponse)
{
string filePath;
Console.WriteLine("");
//Regex setup for removing multiple spaces
RegexOptions options = RegexOptions.None;
Regex regex = new Regex(@"[ ]{2,}", options);
if (chosenFolderName == string.Empty)
{
filePath = string.Concat(chosenFilePath, "");
}
else
{
Directory.CreateDirectory(string.Concat(chosenFilePath, "\\", chosenFolderName));
filePath = string.Concat(chosenFilePath, "\\", chosenFolderName, "\\");
}
foreach (KeyValuePair<string, string> keyValuePair in downloadList)
{
string tempFilePath = filePath;
RestClient client = new RestClient(keyValuePair.Value);
RestRequest request = new RestRequest(Method.GET);
request.AddCookie(loginResponse.Cookies[0].Name, loginResponse.Cookies[0].Value);
Uri uri = client.Execute(request).ResponseUri;
tempFilePath = string.Concat(tempFilePath, uri.Segments.Last<string>());
WebClient webClient = new WebClient();
webClient.Headers.Add(HttpRequestHeader.Cookie, string.Concat(loginResponse.Cookies[0].Name, "=", loginResponse.Cookies[0].Value));
webClient.DownloadFile(uri, regex.Replace(HttpUtility.HtmlDecode(HttpUtility.UrlDecode(tempFilePath)),@" "));
Program.ConsoleSetColor(ConsoleColor.Gray);
Console.WriteLine(HttpUtility.UrlDecode(string.Concat(uri.Segments.Last<string>(), " complete")));
}
}
示例3: ResponseShim
internal ResponseShim(IRestResponse resp,
IRequestShim req,
string baseUrl,
Exception error)
{
this.Request = req;
if (resp != null)
{
this.Code = resp.StatusCode;
this.Message = resp.StatusDescription;
//this.Content = Convert.ToBase64String(resp.RawBytes);
this.Content = UTF8Encoding.UTF8.GetString(
resp.RawBytes, 0, resp.RawBytes.Length);
this.IsSuccess = resp.IsSuccess;
}
this.BaseUrl = baseUrl;
this.Error = error;
var restErr = error as RestServiceException;
if (restErr != null)
{
this.Code = restErr.Code;
this.Message = restErr.Message;
}
}
示例4: ParseXmlForErrorsNode
private static void ParseXmlForErrorsNode(IRestResponse response) {
var errors = new List<string>();
var xml = new XmlDocument();
string filteredXmlContent = GetXmlContentWithoutNamespaces(response.Content);
xml.LoadXml(filteredXmlContent);
//xml.LoadXml(response.Content);
foreach (XmlNode item in xml.SelectNodes("//Error")) {
if (!string.IsNullOrEmpty(item.InnerText)) {
errors.Add(item.InnerText);
}
}
if (errors.Count == 0) {
XmlNode errorsNode = xml.SelectSingleNode("//Errors");
if (errorsNode != null) {
foreach (XmlNode error in errorsNode.SelectNodes("//string")) {
errors.Add(error.InnerText);
}
}
}
if (errors.Count > 0) {
throw new APIException(errors[0], errors);
}
}
示例5: ValidationException
public ValidationException(IRestResponse response)
{
StatusCode = response.StatusCode;
ErrorMessage = response.StatusCode.ToString();
ResponseContent = response.Content;
ValidationError = new List<ObjectValidationError>();
}
示例6: EncodeTaskDataDeserealize
public EncodeTaskData EncodeTaskDataDeserealize(IRestResponse response)
{
EncodeTaskData encodeTaskData;
encodeTaskData = _deserializer.Deserialize<EncodeTaskData>(response);
return encodeTaskData;
}
示例7: When
public When(IRestClient client, IRestRequest request, IRestResponse response)
{
this.client = client;
this.request = request;
this.response = response;
data = new Object();
}
示例8: HullException
public HullException(IRestResponse response, string message)
: base(message)
{
this.StatusCode = response.StatusCode;
this.StatusMessage = response.StatusDescription;
this.ResponseContent = response.Content;
}
示例9: throwOnError
private void throwOnError(IRestResponse response)
{
if (response.ResponseStatus != ResponseStatus.Completed || response.StatusCode != System.Net.HttpStatusCode.OK)
{
throw new ChallongeApiException(response);
}
}
示例10: CheckForErrors
public static void CheckForErrors(IRestResponse response, int errorType)
{
if (response.StatusCode != HttpStatusCode.OK)
{
// object error type { error : {} }
if (errorType == 1) {
var errorObj = JsonConvert.DeserializeObject<ErrorAsObject>(response.Content);
if (errorObj.Error != null && errorObj.Error.Type.Equals("not_found"))
{
throw new NotFoundException(response.StatusCode, new[] { errorObj.Error.Message }, "");
}
else
{
throw new InvalidApiRequestException(response.StatusCode, new[] { errorObj.Error.Message }, "");
}
}
// value error type { error : "", error_description : "" }
if (errorType == 2)
{
var errorObj = JsonConvert.DeserializeObject<ErrorAsValue>(response.Content);
if (errorObj.Error.Equals("access_denied"))
{
throw new InvalidApiRequestException(response.StatusCode, new[] { errorObj.Description }, "");
}
throw new InvalidApiRequestException(response.StatusCode, new[] { errorObj.Description }, "");
}
}
}
示例11: RestException
/// <summary>
/// Initializes a new instance of the <see cref="RestException"/> class.
/// </summary>
/// Simply takes the parameters and stores them in the attributes.
/// <param name="message">The message detailing the problem.</param>
/// <param name="request">The request that caused the problem,</param>
/// <param name="response">The response (if any) that was received.</param>
/// <param name="user">The <see cref="User"/> that attempted the operation.</param>
/// <param name="apiKey">The API key used for the connection.</param>
public RestException(string message, RestRequest request, IRestResponse response, string user, string apiKey) : base(message)
{
this.Request = request;
this.Response = response;
this.User = user;
this.APIKey = apiKey;
}
示例12: LogRequest
private void LogRequest(RestClient restClient, IRestRequest request, IRestResponse response, long durationMs)
{
var requestToLog = new
{
resource = request.Resource,
// Parameters are custom anonymous objects in order to have the parameter type as a nice string
// otherwise it will just show the enum value
parameters = request.Parameters.Select(parameter => new
{
name = parameter.Name,
value = parameter.Value,
type = parameter.Type.ToString()
}),
// ToString() here to have the method as a nice string otherwise it will just show the enum value
method = request.Method.ToString(),
// This will generate the actual Uri used in the request
uri = restClient.BuildUri(request),
};
var responseToLog = new
{
statusCode = response.StatusCode,
content = response.Content,
headers = response.Headers,
// The Uri that actually responded (could be different from the requestUri if a redirection occurred)
responseUri = response.ResponseUri,
errorMessage = response.ErrorMessage,
};
Trace.Write(string.Format("Request completed in {0} ms, Request: {1}, Response: {2}",
durationMs,
JsonConvert.SerializeObject(requestToLog),
JsonConvert.SerializeObject(responseToLog)));
}
示例13: SetUserFriendlyErrorMessage
private void SetUserFriendlyErrorMessage(IRestResponse response)
{
UserFriendlyErrorMessage = "";
string content = response.Content;
//string content = @"{ ""error"": { ""code"": ""20020"", ""message"": ""Insufficient balance"" } }";
string code = "";
string errorMessage = "";
//set clear error messages for our users
if (response.StatusCode == HttpStatusCode.PaymentRequired)
{
GetErrorCodeAndMessage(content, out code, out errorMessage);
if (code == "20020")
{
//original: "Insufficient balance"
this.UserFriendlyErrorMessage = "You have insufficient balance in your Neteller account to complete the transaction. Please deposit funds and try again.";
this.Warning = true; //warning = we don't log a fatal error
}
}
else {
//the errorMessage returned is better than no error message at all usually
if (!string.IsNullOrEmpty(errorMessage))
this.UserFriendlyErrorMessage = errorMessage;
}
}
示例14: IsBadResponse
private static bool IsBadResponse(IRestResponse response, bool errorNotFound = false)
{
return (response.ResponseStatus != ResponseStatus.Completed
|| (errorNotFound && response.StatusCode == HttpStatusCode.NotFound)
|| response.StatusCode == HttpStatusCode.BadRequest
|| response.StatusCode == HttpStatusCode.PaymentRequired);
}
示例15: LatestRecipeIdReceived
private void LatestRecipeIdReceived(IRestResponse response)
{
try
{
int parsedId = int.Parse(response.Content);
string dynamicRecipes = this.settings.GetDynamicRecipes();
Recipe recipeLookUp = null;
List<Recipe> dynamicRecipeList = null;
if (!string.IsNullOrEmpty(dynamicRecipes))
{
XDocument dataDocument = XDocument.Parse(dynamicRecipes);
var recipes = from recipe in dataDocument.Descendants("recipe") select recipe;
dynamicRecipeList = recipes.Select(this.ParseRecipe).ToList();
recipeLookUp = dynamicRecipeList.SingleOrDefault(r => r.Id == parsedId);
}
if (recipeLookUp == null)
{
this.StartGetLatestRecipe(parsedId);
}
else
{
this.recipeList.AddRange(dynamicRecipeList);
this.SortAndSendList();
}
}
catch (FormatException error)
{
this.SortAndSendList();
}
}