本文整理汇总了C#中Request类的典型用法代码示例。如果您正苦于以下问题:C# Request类的具体用法?C# Request怎么用?C# Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于命名空间,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeProvider
/// <summary>
/// Performs one-time initialization of the PROVIDER.
/// </summary>
/// <param name="request">
/// An object passed in from the CORE that contains functions that can be used to interact with
/// the CORE and HOST
/// </param>
public void InitializeProvider(Request request) {
if( request == null ) {
throw new ArgumentNullException("request");
}
// Nice-to-have put a debug message in that tells what's going on.
request.Debug("Calling '{0}::InitializeProvider'", ProviderName);
}
示例2: Fail
private static AppFunc Fail(int status, string body, string headerName = null, string headerValue = null)
{
return env =>
{
Request request = new Request(env);
Response response = new Response(env);
response.StatusCode = status;
response.Headers
.SetHeader("Content-Type", "text/plain")
.SetHeader("Content-Length", body.Length.ToString(CultureInfo.InvariantCulture))
.SetHeader("X-Cascade", "pass");
if (headerName != null && headerValue != null)
{
response.Headers.SetHeader(headerName, headerValue);
}
if ("HEAD".Equals(request.Method, StringComparison.OrdinalIgnoreCase))
{
return TaskHelpers.Completed();
}
return response.WriteAsync(body);
};
}
示例3: Request
public override Request Request(Request request)
{
// (collectionPointer)(key:binary)(inclusive:boolean)(pageSize:int)
base.Request(request);
request.OperationMode = OperationMode.Synchronous;
// collection pointer
request.AddDataItem(FileId);
request.AddDataItem(PageIndex);
request.AddDataItem(PageOffset);
// key binary
var cid = BinarySerializer.ToArray(FirstKey.ClusterId);
var cpos = BinarySerializer.ToArray(FirstKey.ClusterPosition);
byte[] orid = new byte[cid.Length + cpos.Length];
Array.Copy(cid, orid, cid.Length);
Array.Copy(cpos, 0, orid, cid.Length, cpos.Length);
request.AddDataItem(orid);
// inclusive
request.AddDataItem((byte)(Inclusive ? 1 : 0)); // 0 - false 1 - true
// page size
if (OClient.ProtocolVersion >= 21)
request.AddDataItem((int)128);
return request;
}
示例4: Request
public override Request Request(Request request)
{
base.Request(request);
request.AddDataItem(ConfigKey);
return request;
}
示例5: StartListening
public void StartListening()
{
while (true)
{
using (Socket clientSocket = listeningSocket.Accept())
{
IPEndPoint clientIP = clientSocket.RemoteEndPoint as IPEndPoint;
Debug.Print("Received request from " + clientIP.ToString());
var x = clientSocket.RemoteEndPoint;
int availableBytes = clientSocket.Available;
Debug.Print(DateTime.Now.ToString() + " " + availableBytes.ToString() + " request bytes available");
int bytesReceived = (availableBytes > maxRequestSize ? maxRequestSize : availableBytes);
if (bytesReceived > 0)
{
byte[] buffer = new byte[bytesReceived]; // Buffer probably should be larger than this.
int readByteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None);
using (Request r = new Request(clientSocket, Encoding.UTF8.GetChars(buffer)))
{
Debug.Print(DateTime.Now.ToString() + " " + r.URL);
if (requestReceived != null) requestReceived(r);
}
}
}
// I always like to have this in a continuous loop. Helps prevent lock-ups
Thread.Sleep(10);
}
}
示例6: Create
/// <summary>
/// Create a Parcel.
/// </summary>
/// <param name="parameters">
/// Dictionary containing parameters to create the parcel with. Valid pairs:
/// * {"length", int}
/// * {"width", int}
/// * {"height", int}
/// * {"weight", double}
/// * {"predefined_package", string}
/// All invalid keys will be ignored.
/// </param>
/// <returns>EasyPost.Parcel instance.</returns>
public static Parcel Create(IDictionary<string, object> parameters)
{
Request request = new Request("parcels", Method.POST);
request.addBody(parameters, "parcel");
return request.Execute<Parcel>();
}
示例7: RetrieveReference
/// <summary>
/// Retrieve a Item from a custom reference.
/// </summary>
/// <param name="name">String containing the name of the custom reference to search for.</param>
/// <param name="value">String containing the value of the custom reference to search for.</param>
/// <returns>EasyPost.Item instance.</returns>
public static Item RetrieveReference(string name, string value) {
Request request = new Request("items/retrieve_reference/?{name}={value}");
request.AddUrlSegment("name", name);
request.AddUrlSegment("value", value);
return request.Execute<Item>();
}
示例8: MXLookup
public static MXRecord[] MXLookup(string domain, IPAddress dns_server) {
// check the inputs
if (domain == null || dns_server == null)
throw new ArgumentNullException((domain == null) ? "dns_server" : "domain");
// create a request for this
Request request = new Request();
// do the MX IN lookup for the suplied domain
request.AddQuestion(new Question(domain, DnsType.MX, DnsClass.IN));
Response response = Lookup(request, dns_server);
if (response == null)
return null;
List<MXRecord> resource_records = new List<MXRecord>();
foreach(Answer answer in response.Answers) {
if (answer.Record is MXRecord) {
resource_records.Add(answer.Record as MXRecord);
}
}
// sort into lowest preference order
resource_records.Sort();
return resource_records.ToArray();
}
示例9: HandleRequest
public override void HandleRequest(Request request)
{
if (request.Message.StartsWith("~geoip") && request.RequestFrom.AccessLevel >= AccessLevel.Public)
{
Match expressionMatch = GeoIpRegex.Match(request.Message);
if (expressionMatch.Success)
{
try
{
ExecuteSearch(expressionMatch.Groups[1].Value, request);
}
catch (Exception ex)
{
ModuleManagementContainer.HandleResponse(request.CreateResponse(ResponseType.Public,
"{0}, The service is currently b00rked, please try again in a few minutes.", request.Nick));
Logger.WarnFormat("Search threw an exception. Nick: {0}, terms: \"{1}\", stack message: {2}",
request.Nick, expressionMatch.Groups[1].Value, ex.StackTrace);
}
}
else
{
// If the message format isn't correct, notify the user.
ModuleManagementContainer.HandleResponse(request.CreateResponse(ResponseType.Public,
String.Format("{0}, invalid geoip syntax, please try again.",
request.Nick)));
}
}
}
示例10: HandleRequest
static void HandleRequest(Request request, Response response)
{
// receive HTTP content
byte[] content = request.Stdin.GetContents();
// access server variables
string serverSoftware = request.ServerSoftware.GetValueOrDefault();
string method = request.RequestMethod.Value;
// access HTTP headers
string userAgent = request.Headers[RequestHeader.HttpUserAgent];
string cookieValue = request.GetCookieValue("Keks").GetValueOrDefault();
// set HTTP headers
response.SetHeader(ResponseHeader.HttpExpires,
Response.ToHttpDate(DateTime.Now.AddDays(1.0)));
response.SetCookie(new Cookie("Keks", "yummy"));
// send HTTP content
response.PutStr(
@"<html>
<body>
<p>Hello World!</p>
<p>Server: " + serverSoftware + @"</p>
<p>User Agent: " + userAgent + @"</p>
<p>Received cookie value: " + cookieValue + @"</p>
<p>Content length as read: " + content.Length + @"</P>
<p>Request method: " + method + @"</p>
</body>
</html>"
);
}
示例11: Get
internal ArangoCollection Get(string name)
{
var request = new Request(RequestType.Collection, HttpMethod.Get);
request.RelativeUri = string.Join("/", _apiUri, name);
var response = _connection.Process(request);
var collection = new ArangoCollection();
switch (response.StatusCode)
{
case HttpStatusCode.OK:
collection.Id = response.Document.String("id");
collection.Name = response.Document.String("name");
collection.Status = response.Document.Enum<ArangoCollectionStatus>("status");
collection.Type = response.Document.Enum<ArangoCollectionType>("type");
break;
case HttpStatusCode.NotFound:
collection = null;
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return collection;
}
示例12: OnFailure
public void OnFailure(Request request, Java.IO.IOException exception)
{
if (onFailure != null)
{
onFailure(request, exception);
}
}
示例13: Handle
/// <summary>
/// Tries to handle request.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The WebServer.BusinessLogic.Response.
/// </returns>
public override Response Handle(Request request)
{
if (request.HttpPath.EndsWith("/"))
{
string path = Configurator.Instance.RelativeWwwPath + request.HttpPath.Replace("/", "\\");
if(!Directory.Exists(path))
{
return NextHandler.Handle(request);
}
DirectoryInfo directory = new DirectoryInfo(path);
List<FileSystemInfo> descendants = new List<FileSystemInfo>();
descendants.AddRange(directory.GetFileSystemInfos());
if (descendants.Select(desc => desc.Name).Contains("index.html"))
{
request.HttpPath += "index.html";
return NextHandler.Handle(request);
}
string webPage = this.CreateWebPage(descendants, request);
Response toReturn = new Response("text/html", request.HttpVersion, Encoding.UTF8.GetBytes(webPage));
if (Configurator.Instance.UseResponseCompression && request.AcceptEncoding == EnumAcceptEncoding.Gzip)
{
toReturn.Data = GzipCompress(toReturn.Data);
toReturn.ContentEncoding = "gzip";
}
return toReturn;
}
return NextHandler.Handle(request);
}
示例14: ExtractCredentialsFromHeaders
private static string[] ExtractCredentialsFromHeaders(Request request)
{
var authorization =
request.Headers.Authorization;
if (string.IsNullOrEmpty(authorization))
{
return null;
}
if (!authorization.StartsWith(SCHEME))
{
return null;
}
try
{
var encodedUserPass = authorization.Substring(SCHEME.Length).Trim();
var userPass = Encoding.UTF8.GetString(Convert.FromBase64String(encodedUserPass));
return String.IsNullOrWhiteSpace(userPass) ? null : userPass.Split(':');
}
catch (FormatException)
{
return null;
}
}
示例15: Delete
internal bool Delete(string id)
{
var request = new Request(RequestType.Edge, HttpMethod.Delete);
request.RelativeUri = string.Join("/", _apiUri, id);
var response = _connection.Process(request);
var isRemoved = false;
switch (response.StatusCode)
{
case HttpStatusCode.OK:
case HttpStatusCode.Accepted:
isRemoved = true;
break;
default:
if (response.IsException)
{
throw new ArangoException(
response.StatusCode,
response.Document.String("driverErrorMessage"),
response.Document.String("driverExceptionMessage"),
response.Document.Object<Exception>("driverInnerException")
);
}
break;
}
return isRemoved;
}