本文整理汇总了C#中System.Net.Request类的典型用法代码示例。如果您正苦于以下问题:C# Request类的具体用法?C# Request怎么用?C# Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于System.Net命名空间,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
private void ProcessRequest(Request request, NetworkStream stream)
{
if (request == null)
{
return;
}
if (request.Path.Equals("/"))
request.Path = floderPath+"/index.html";
ParsePath(request);
if (File.Exists(floderPath+request.Path))
{
if(Path.GetExtension(request.Path).ToUpper()==".HTML")
{
var fileContent = File.ReadAllText(floderPath + request.Path);
GenerateResponse(fileContent, stream, OK200);
return;
}
else
{
byte[] byteContents = File.ReadAllBytes(floderPath + request.Path.Replace(@"/",@"\"));
GenerateResponse(byteContents, stream, OK200);
return;
}
}
GenerateResponse("Not found", stream, NOTFOUND404);
}
示例2: QueryStringForTR
public static String QueryStringForTR(Request trParams, Request req, String postURL, BraintreeService service)
{
String trData = TrUtil.BuildTrData(trParams, "http://example.com", service);
String postData = "tr_data=" + HttpUtility.UrlEncode(trData, Encoding.UTF8) + "&";
postData += req.ToQueryString();
var request = WebRequest.Create(postURL) as HttpWebRequest;
request.Method = "POST";
request.KeepAlive = false;
byte[] buffer = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = buffer.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
var response = request.GetResponse() as HttpWebResponse;
String query = response.ResponseUri.Query;
response.Close();
return query;
}
示例3: Process
public Response.CsResponse Process(Request.CsRequest request)
{
string[] lines = File.ReadAllLines("serverlist.txt");
CsResponse response = new CsResponse();
foreach (var l in lines)
{
if (l.Trim().Length == 0 || l.Trim()[0] == '#')
continue;
var ipPort = l.Trim().Split(new char[] { ':' });
IPAddress ip;
short port;
if (ipPort.Length < 2 || !IPAddress.TryParse(ipPort[0], out ip) || !short.TryParse(ipPort[1], out port))
continue;
response.Servers.Add(new CsResponseItem()
{
IPAddress = ip,
Port = port
});
}
return response;
}
示例4: GetUUID
/// <summary>
/// Retrieve the UUID given a username
/// This one is no longer used during auth since the new method get the UUID
/// </summary>
public static Guid GetUUID(string username)
{
using (WebClient client = new WebClient())
{
/*
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => '{"name":"'.$username.'","agent":"minecraft"}',
context = stream_context_create(options);
result = file_get_contents(url, false, $context);
return res;
*/
var request = new Request();
request.name = username;
byte[] req = Json.Serialize(request);
// Download data.
byte[] resp = client.UploadData(url, req);
var response = Json.Deserialize<Response>(resp);
if(response.profiles.Count == 0)
throw new InvalidOperationException("Bad response: " + Encoding.UTF8.GetString(resp));
Guid id = response.profiles[0].id;
if (id == Guid.Empty)
throw new InvalidOperationException("Bad response: " + Encoding.UTF8.GetString(resp));
return id;
}
}
示例5: JSONRequest
private static void JSONRequest(Request reqst)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Request));
MemoryStream mem = new MemoryStream();
ser.WriteObject(mem, reqst);
string jsonData = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
byte[] byteArray = Encoding.UTF8.GetBytes(jsonData);
mem.Close();
mem.Dispose();
Console.WriteLine(jsonData);
string json = HTTPRequestResponse(string.Format("{0}/{1}/{2}", _URL, _userID, "json"), byteArray, "PUT", "application/json;charset=\"utf-8\"");
Console.WriteLine(json);
DataContractJsonSerializer respSer = new DataContractJsonSerializer(typeof(Response));
Response resp = (Response)respSer.ReadObject(new MemoryStream(Encoding.Unicode.GetBytes(json)));
if (resp.IsSuccessful)
{
string responseData = _aes.Decrypt(resp.Data, _key);
Console.WriteLine(responseData);
}
else
Console.WriteLine(resp.ErrorMessage);
}
示例6: RequestWriter
public RequestWriter(IRequest rawRequest)
: this()
{
Method = rawRequest.Method;
Uri = rawRequest.Uri;
TheRealBodyBytes = new Request(rawRequest).BodyBytes;
}
示例7: Analyze
public PageResult Analyze(Request request, Response response)
{
Console.WriteLine(@"FakePageAnalyzer.Analyze 执行分析");
request = new Request()
{
SiteId = SiteIndex.Usashopcn,
Url = @"http://www.usashopcn.com/Product/Details/127824",
HttpMethod = HttpMethod.Get,
RemainRetryCount = 0
};
response = new Response()
{
Request = request,
HttpStatusCode = HttpStatusCode.OK,
ReasonPhrase = "OK",
IsSuccessCode = true,
Content = "测试文本",
MillisecondTime = 1000,
Downloader = "FakeDownloader"
};
return new PageResult()
{
Topic = TopicType.StaticHtml,
Request = request,
Response = response
};
}
示例8: GetStream
/// <summary>
/// GetStream
/// </summary>
/// <param name="request">request</param>
/// <returns>Stream</returns>
internal static Stream GetStream(Request request)
{
HttpWebResponse response = null;
Stream responseStream = null;
try
{
var httpWebRequest = GetHttpWebRequest(request);
response = (HttpWebResponse)httpWebRequest.GetResponse();
responseStream = response.GetResponseStream();
byte[] buffer = StreamToBytes(responseStream);
Stream memoryStream = new MemoryStream(buffer);
request.Cookie = httpWebRequest.CookieContainer;
return memoryStream;
}
catch (Exception)
{
return null;
}
finally
{
if (responseStream != null)
{
responseStream.Dispose();
responseStream.Close();
}
if (response != null)
{
response.Dispose();
response.Close();
}
}
}
示例9: RequestReceivedEventArgs
public RequestReceivedEventArgs(Request request, Socket client, int byteCount)
{
this.request = request;
this.client = client;
this.byteCount = byteCount;
this.receiveTime = DateTime.Now;
}
示例10: ProcessRequest
public override Task<Response> ProcessRequest(Request request)
{
if (this.RequestReceived != null)
{
return Task.FromResult(this.RequestReceived(request));
}
return Task.FromResult(request.CreateErrorResponse(HttpStatusCode.Gone, "Gone fishin'."));
}
示例11: App
public static AppAction App()
{
return (env, fault, result) => {
var request = new Request(env);
var response = new Response(result);
if (string.IsNullOrWhiteSpace(request.GET["Url"])) {
response.ContentType = "text/html";
response
.Write("<form>")
.Write("Url <input type='text' name='Url' style='width:50%;' value='http://download.microsoft.com/download/f/e/6/fe6eb291-e187-4b06-ad78-bb45d066c30f/6.0.6001.18000.367-KRMSDK_EN.iso'/><br/>")
.Write("Save as <input type='text' name='SaveAs' style='width:50%;' value='6.0.6001.18000.367-KRMSDK_EN.iso'/><br/>")
.Write("<input type='submit' value='Go'/>")
.Write("</form>")
.Finish();
}
else {
// make remote request asynchronously
var remoteRequest = WebRequest.Create(request.GET["Url"]);
remoteRequest.BeginGetResponse(getResponseResult => fault.Guard(() => {
var remoteResponse = (HttpWebResponse)remoteRequest.EndGetResponse(getResponseResult);
// pass some response headers along
response.Status = (int)remoteResponse.StatusCode;
response.ContentType = remoteResponse.ContentType;
if (!string.IsNullOrWhiteSpace(request.GET["SaveAs"])) {
response.AddHeader("Content-Disposition", "attachment; filename=" + request.GET["SaveAs"]);
}
// pass response body along
var remoteStream = remoteResponse.GetResponseStream();
if (remoteStream == null) {
response.Finish();
}
else {
var buffer = new byte[4096];
response.Finish((next, error, complete) =>
Loop.Run((halted, continuation) => error.Guard(() =>
remoteStream.BeginRead(buffer, 0, buffer.Length, streamResult => error.Guard(() => {
var count = remoteStream.EndRead(streamResult);
if (halted()) {
return;
}
if (count <= 0) {
complete();
return;
}
if (!next.InvokeAsync(new ArraySegment<byte>(buffer, 0, count), continuation)) {
continuation();
}
}), null))));
}
}), null);
}
};
}
示例12: ProcessRequest
public override Task<Response> ProcessRequest(Request request)
{
// The '.Servers' property actually returns a new list so this is totally reasonable.
var response = new ListServerResponse {Servers = this.serverList.Servers};
if (response.Servers.Count == 0)
{
return Task.FromResult(request.CreateErrorResponse(HttpStatusCode.NotFound, "No known servers."));
}
return Task.FromResult(Response.Create(request, HttpStatusCode.OK, response));
}
示例13: GetFeatures
/// <summary>
/// Returns a collection of strings to the client advertizing features this provider supports.
/// </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 GetFeatures(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}::GetFeatures' ", ProviderName);
foreach (var feature in _features) {
request.Yield(feature);
}
}
示例14: DoSendResponse
public void DoSendResponse(Request request, Response response)
{
// the http stack is intended to send back only coap responses
// fill the exchanger with the incoming response
WaitFuture<Request, Response> wf;
if (_exchangeMap.TryRemove(request, out wf))
{
wf.Response = response;
}
}
示例15: AddStream
internal UInt32 AddStream(Request request, Type type)
{
var id = this.connection.KRPC ().AddStream (request);
lock (accessLock) {
if (!streamTypes.ContainsKey (id)) {
streamTypes [id] = type;
streamData [id] = this.connection.Invoke (request);
}
}
return id;
}