本文整理汇总了C#中IHttpRequest类的典型用法代码示例。如果您正苦于以下问题:C# IHttpRequest类的具体用法?C# IHttpRequest怎么用?C# IHttpRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IHttpRequest类属于命名空间,在下文中一共展示了IHttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequestFilter
public static void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto)
{
var validator = ValidatorCache.GetValidator(req, requestDto.GetType());
if (validator == null) return;
var validatorWithHttpRequest = validator as IRequiresHttpRequest;
if (validatorWithHttpRequest != null)
validatorWithHttpRequest.HttpRequest = req;
var ruleSet = req.HttpMethod;
var validationResult = validator.Validate(
new ValidationContext(requestDto, null, new MultiRuleSetValidatorSelector(ruleSet)));
if (validationResult.IsValid) return;
var errorResponse = DtoUtils.CreateErrorResponse(
requestDto, validationResult.ToErrorResult());
var validationFeature = EndpointHost.GetPlugin<ValidationFeature>();
if (validationFeature != null && validationFeature.ErrorResponseFilter != null)
{
errorResponse = validationFeature.ErrorResponseFilter(validationResult, errorResponse);
}
res.WriteToResponse(req, errorResponse);
}
示例2: GetResponse
public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
{
var requestContentType = ContentType.GetEndpointAttributes(httpReq.ResponseContentType);
return ExecuteService(request,
HandlerAttributes | requestContentType | GetEndpointAttributes(httpReq), httpReq, httpRes);
}
示例3: DeserializeHttpRequest
public static object DeserializeHttpRequest(Type operationType, IHttpRequest httpReq, string contentType)
{
var httpMethod = httpReq.HttpMethod;
var queryString = httpReq.QueryString;
if (httpMethod == HttpMethods.Get || httpMethod == HttpMethods.Delete || httpMethod == HttpMethods.Options)
{
try
{
return KeyValueDataContractDeserializer.Instance.Parse(queryString, operationType);
}
catch (Exception ex)
{
var msg = "Could not deserialize '{0}' request using KeyValueDataContractDeserializer: '{1}'.\nError: '{2}'"
.Fmt(operationType, queryString, ex);
throw new SerializationException(msg);
}
}
var isFormData = httpReq.HasAnyOfContentTypes(ContentType.FormUrlEncoded, ContentType.MultiPartFormData);
if (isFormData)
{
try
{
return KeyValueDataContractDeserializer.Instance.Parse(httpReq.FormData, operationType);
}
catch (Exception ex)
{
throw new SerializationException("Error deserializing FormData: " + httpReq.FormData, ex);
}
}
var request = CreateContentTypeRequest(httpReq, operationType, contentType);
return request;
}
示例4: SimplePreRequestFilter
private void SimplePreRequestFilter(IHttpRequest req, IHttpResponse res)
{
if (Path.GetFileName(req.PathInfo).StartsWith("_"))
{
throw new HttpException("Files with leading underscores ('_') cannot be served.");
}
}
示例5: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
response.ContentType = "text/plain";
response.StatusCode = 403;
response.Write("Forbidden\n\n");
response.Write("\nRequest.HttpMethod: " + request.HttpMethod);
response.Write("\nRequest.PathInfo: " + request.PathInfo);
response.Write("\nRequest.QueryString: " + request.QueryString);
response.Write("\nRequest.RawUrl: " + request.RawUrl);
if (IsIntegratedPipeline.HasValue)
response.Write("\nApp.IsIntegratedPipeline: " + IsIntegratedPipeline);
if (!WebHostPhysicalPath.IsNullOrEmpty())
response.Write("\nApp.WebHostPhysicalPath: " + WebHostPhysicalPath);
if (!WebHostRootFileNames.IsEmpty())
response.Write("\nApp.WebHostRootFileNames: " + TypeSerializer.SerializeToString(WebHostRootFileNames));
if (!ApplicationBaseUrl.IsNullOrEmpty())
response.Write("\nApp.ApplicationBaseUrl: " + ApplicationBaseUrl);
if (!DefaultRootFileName.IsNullOrEmpty())
response.Write("\nApp.DefaultRootFileName: " + DefaultRootFileName);
if (!DefaultHandler.IsNullOrEmpty())
response.Write("\nApp.DefaultHandler: " + DefaultHandler);
if (!ServiceStackHttpHandlerFactory.DebugLastHandlerArgs.IsNullOrEmpty())
response.Write("\nApp.DebugLastHandlerArgs: " + ServiceStackHttpHandlerFactory.DebugLastHandlerArgs);
ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(response);
//Apache+mod_mono doesn't like this
//response.OutputStream.Flush();
//response.Close();
}
示例6: ProcessRequest
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
try
{
EndpointHost.Config.AssertFeatures(format);
if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) return;
httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
var callback = httpReq.QueryString["callback"];
var doJsonp = EndpointHost.Config.AllowJsonpRequests
&& !string.IsNullOrEmpty(callback);
var request = CreateRequest(httpReq, operationName);
if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;
var response = GetResponse(httpReq, httpRes, request);
if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;
if (doJsonp && !(response is CompressedResult))
httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
else
httpRes.WriteToResponse(httpReq, response);
}
catch (Exception ex)
{
if (!EndpointHost.Config.WriteErrorsToResponse) throw;
HandleException(httpReq, httpRes, operationName, ex);
}
}
示例7: WriteToResponse
public static bool WriteToResponse(this IHttpResponse httpRes, IHttpRequest httpReq, object result, byte[] bodyPrefix, byte[] bodySuffix)
{
if (result == null)
{
httpRes.EndHttpRequestWithNoContent();
return true;
}
var serializationContext = new HttpRequestContext(httpReq, httpRes, result);
var httpResult = result as IHttpResult;
if (httpResult != null)
{
if (httpResult.ResponseFilter == null)
{
httpResult.ResponseFilter = EndpointHost.AppHost.ContentTypeFilters;
}
httpResult.RequestContext = serializationContext;
serializationContext.ResponseContentType = httpResult.ContentType ?? httpReq.ResponseContentType;
var httpResSerializer = httpResult.ResponseFilter.GetResponseSerializer(serializationContext.ResponseContentType);
return httpRes.WriteToResponse(httpResult, httpResSerializer, serializationContext, bodyPrefix, bodySuffix);
}
var serializer = EndpointHost.AppHost.ContentTypeFilters.GetResponseSerializer(httpReq.ResponseContentType);
return httpRes.WriteToResponse(result, serializer, serializationContext, bodyPrefix, bodySuffix);
}
示例8: CreateTemporarySessionId
public static string CreateTemporarySessionId(this IHttpResponse res, IHttpRequest req)
{
var sessionId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
res.Cookies.AddSessionCookie(SessionFeature.SessionId, sessionId);
req.Items[SessionFeature.SessionId] = sessionId;
return sessionId;
}
示例9: GetQueryValue
public static string GetQueryValue(IHttpRequest req, string name)
{
string value;
if (req.QueryData.TryGetValue (name, out value))
return value;
return string.Empty;
}
示例10: GetResponse
public override object GetResponse(IHttpRequest httpReq, object request)
{
var response = ExecuteService(request,
HandlerAttributes | GetEndpointAttributes(httpReq), httpReq);
return response;
}
示例11: CreateSessionId
/// <summary>
/// Create the active Session or Permanent Session Id cookie.
/// </summary>
/// <returns></returns>
public static string CreateSessionId(this IHttpResponse res, IHttpRequest req)
{
var sessionOptions = GetSessionOptions(req);
return sessionOptions.Contains(SessionOptions.Permanent)
? res.CreatePermanentSessionId(req)
: res.CreateTemporarySessionId(req);
}
示例12: GetRequest
public object GetRequest(IHttpRequest httpReq, string operationName)
{
var operationType = GetOperationType(operationName);
AssertOperationExists(operationName, operationType);
return DeserializeContentType(operationType, httpReq, HandlerContentType);
}
示例13: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
var applicationRequest = requestDto as ApplicationRequest;
var appKey = GetAppKeyFromRequest(req, applicationRequest);
var appSecret = GetAppSecretFromRequest(req, applicationRequest);
var app = ApplicationAuthenticationService.Authenticate(appKey,appSecret);
if (app == null)
{
res.StatusCode = (int)HttpStatusCode.Forbidden;
// Some Android devices require a body, otherwise the response code is ignored and set 0
res.Write(HttpStatusCode.Forbidden.ToString());
res.Close();
}
if (applicationRequest != null)
{
applicationRequest.AppKey = appKey;
applicationRequest.AppSecret = appSecret;
applicationRequest.Application = ApplicationRepository.FindApplication(appKey, appSecret);
applicationRequest.Account = AccountApplicationRepository.GetForApplication(applicationRequest.Application.Id);
}
var validationErrors = ValidateRequest(applicationRequest);
if (validationErrors.Any())
{
res.StatusCode = (int)HttpStatusCode.BadRequest;
// Some Android devices require a body, otherwise the response code is ignored and set 0
res.Write(HttpStatusCode.BadRequest.ToString());
foreach (var error in validationErrors)
{
res.Write(error);
}
res.Close();
}
}
示例14: ExecuteSync
/// <summary>
/// 同步的请求方式
/// </summary>
/// <param name="request">请求的参数</param>
/// <returns>自定义的Response结果</returns>
public IHttpResponse ExecuteSync(IHttpRequest request)
{
IHttpResponse response = new HttpResponse();
try
{
if (string.IsNullOrEmpty(request.AddressUrl)
|| request.HttpMothed == HttpMothed.None)
{
response.ResponseStatus = ResponseStatus.Error;
response.ErrorException = new Exception("对不起,请求出错,请检查参数等设置(地址,请求方式等)!");
return response;
}
HttpWebRequest webrequest = ConfigureWebRequest(request);
SendBodyDataSync(webrequest, request);
GetResponse(webrequest, ref response);
}
catch (Exception ex)
{
response.ErrorException = ex;
response.ResponseStatus = ResponseStatus.Error;
}
return response;
}
示例15: RenderOperation
protected override void RenderOperation(System.Web.UI.HtmlTextWriter writer, IHttpRequest httpReq, string operationName, string requestMessage, string responseMessage, string metadataHtml)
{
var operationControl = new Soap12OperationControl
{
HttpRequest = httpReq,
MetadataConfig = EndpointHost.Config.ServiceEndpointsMetadataConfig,
Title = EndpointHost.Config.ServiceName,
Format = this.Format,
OperationName = operationName,
HostName = httpReq.GetUrlHostName(),
RequestMessage = requestMessage,
ResponseMessage = responseMessage,
MetadataHtml = metadataHtml,
};
if (!this.ContentType.IsNullOrEmpty())
{
operationControl.ContentType = this.ContentType;
}
if (!this.ContentFormat.IsNullOrEmpty())
{
operationControl.ContentFormat = this.ContentFormat;
}
operationControl.Render(writer);
}