本文整理汇总了C#中IRestResponse类的典型用法代码示例。如果您正苦于以下问题:C# IRestResponse类的具体用法?C# IRestResponse怎么用?C# IRestResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IRestResponse类属于命名空间,在下文中一共展示了IRestResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetDefaultResponse
private static HttpServerResponse GetDefaultResponse(IRestResponse response)
{
var serverResponse = HttpServerResponse.Create(response.StatusCode);
serverResponse.Date = DateTime.Now;
serverResponse.IsConnectionClosed = true;
return serverResponse;
}
开发者ID:anondesigns,项目名称:restup,代码行数:8,代码来源:RestToHttpResponseConverter.cs
示例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")));
}
}
开发者ID:nishanthkarthik,项目名称:moodlesharp-cli,代码行数:32,代码来源:Program.cs
示例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;
}
}
开发者ID:peterson1,项目名称:ErrH,代码行数:27,代码来源:ResponseShim.cs
示例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);
}
}
开发者ID:usbsnowcrash,项目名称:Careerbuilder.Net,代码行数:27,代码来源:ErrorParser.cs
示例5: ValidationException
public ValidationException(IRestResponse response)
{
StatusCode = response.StatusCode;
ErrorMessage = response.StatusCode.ToString();
ResponseContent = response.Content;
ValidationError = new List<ObjectValidationError>();
}
开发者ID:fredsakr,项目名称:eloqua-csharp-rest-client,代码行数:7,代码来源:ValidationException.cs
示例6: EncodeTaskDataDeserealize
public EncodeTaskData EncodeTaskDataDeserealize(IRestResponse response)
{
EncodeTaskData encodeTaskData;
encodeTaskData = _deserializer.Deserialize<EncodeTaskData>(response);
return encodeTaskData;
}
开发者ID:GusLab,项目名称:video-portal,代码行数:7,代码来源:EncodeDeserializer.cs
示例7: When
public When(IRestClient client, IRestRequest request, IRestResponse response)
{
this.client = client;
this.request = request;
this.response = response;
data = new Object();
}
开发者ID:sakthijas,项目名称:ProtoTest.Golem,代码行数:7,代码来源:When.cs
示例8: HullException
public HullException(IRestResponse response, string message)
: base(message)
{
this.StatusCode = response.StatusCode;
this.StatusMessage = response.StatusDescription;
this.ResponseContent = response.Content;
}
开发者ID:Earthware,项目名称:hull-csharp,代码行数:7,代码来源:HullException.cs
示例9: throwOnError
private void throwOnError(IRestResponse response)
{
if (response.ResponseStatus != ResponseStatus.Completed || response.StatusCode != System.Net.HttpStatusCode.OK)
{
throw new ChallongeApiException(response);
}
}
开发者ID:zoharmodifier,项目名称:SkillKeeper,代码行数:7,代码来源:ChallongePortal.cs
示例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 }, "");
}
}
}
开发者ID:skraloupak,项目名称:AngelList,代码行数:32,代码来源:ErrorChecker.cs
示例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;
}
开发者ID:Wierdbeard65,项目名称:Labinator2016,代码行数:16,代码来源:RestException.cs
示例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)));
}
开发者ID:CactusSoft,项目名称:Cactus.Fileserver,代码行数:34,代码来源:CrudIntegrationTest.cs
示例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;
}
}
开发者ID:Sire,项目名称:neteller-rest-api,代码行数:29,代码来源:NetellerException.cs
示例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);
}
开发者ID:plachmann,项目名称:crds-angular,代码行数:7,代码来源:StripeService.cs
示例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();
}
}
开发者ID:kalkie,项目名称:WeeklyThaiRecipe-WP,代码行数:34,代码来源:RecipeService.cs
示例16: Parse
public static Table Parse(IRestResponse response)
{
Table table = new Table();
StringReader reader = new StringReader(response.Content);
string readLine = reader.ReadLine();
if (readLine != null)
{
string[] collection = readLine.Split(Separator);
foreach (string column in collection)
{
table.Columns.Add(column.TrimStart('"').TrimEnd('"'));
}
}
string line = reader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
Row row = new Row(line);
table.Rows.Add(row);
line = reader.ReadLine();
}
return table;
}
开发者ID:Genbox,项目名称:SPARQL.NET,代码行数:26,代码来源:CSVParser.cs
示例17: Parse
public List<Dictionary<string, object>> Parse(IRestResponse<dynamic> responseToParse, ParserRules ruleset)
{
if (responseToParse.ResponseStatus != ResponseStatus.Completed)
throw new ApplicationException("Response was not [Completed]");
if (responseToParse.Data == null)
throw new ApplicationException("Response data could not be parsed");
var resultset = responseToParse.Data as IEnumerable<dynamic>;
if (resultset == null)
throw new ApplicationException("Response data could not be identified as collection");
List<Dictionary<string, object>> l = new List<Dictionary<string, object>>();
foreach (Dictionary<string, object> item in resultset)
{
var newItem = new Dictionary<string, object>();
foreach (var field in ruleset.Fields)
{
if (item.ContainsKey(field.Selector))
{
newItem.Add(field.Selector, item[field.Selector]);
}
}
if (newItem.Any())
l.Add(newItem);
}
return l;
}
开发者ID:BartDeVries,项目名称:RESTGateway,代码行数:31,代码来源:Parser.cs
示例18: ReadHandler
public void ReadHandler(IRestResponse<List<Score>> response, RestRequestAsyncHandle handle)
{
Debug.Log("In ReadHandler");
_scores = response.Data;
Debug.Log(_scores);
}
开发者ID:ProjectStratus,项目名称:oneweek,代码行数:7,代码来源:HighScoresSceneUI.cs
示例19: BaseCompare
public bool BaseCompare(IRestResponse mockResponse, IRestResponse response)
{
return response.ContentLength != 0 &&
mockResponse.ErrorException == response.ErrorException &&
mockResponse.ErrorMessage == response.ErrorMessage &&
mockResponse.ResponseStatus.Equals(response.ResponseStatus);
}
开发者ID:pjarosinski,项目名称:MindbodyAPITestSuite,代码行数:7,代码来源:BaseTestSuite.cs
示例20: BadResponse
static string BadResponse(IRestResponse response, string pre)
{
string ret = null;
if (response.StatusCode != System.Net.HttpStatusCode.OK)
Log.Write(LogSeverity.Error, ret = (pre+response.ErrorMessage));
return ret;
}
开发者ID:Kusoneko,项目名称:Nekobot,代码行数:7,代码来源:Chatbot.cs
注:本文中的IRestResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论