本文整理汇总了C#中System.Net.Request类的典型用法代码示例。如果您正苦于以下问题:C# Request类的具体用法?C# Request怎么用?C# Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于System.Net命名空间,在下文中一共展示了Request类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:pekingston,项目名称:Drop-Project,代码行数:28,代码来源:PedroServer.cs
示例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;
}
开发者ID:sdether,项目名称:braintree_dotnet,代码行数:25,代码来源:TestHelper.cs
示例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;
}
开发者ID:saicoder,项目名称:hlmasterserver.net,代码行数:26,代码来源:SimpleFromFile.cs
示例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;
}
}
开发者ID:mctraveler,项目名称:MineSharp,代码行数:35,代码来源:UsernameUUID.cs
示例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);
}
开发者ID:bespencer1,项目名称:Csharp,代码行数:26,代码来源:Program.cs
示例6: RequestWriter
public RequestWriter(IRequest rawRequest)
: this()
{
Method = rawRequest.Method;
Uri = rawRequest.Uri;
TheRealBodyBytes = new Request(rawRequest).BodyBytes;
}
开发者ID:remitaylor,项目名称:knack,代码行数:7,代码来源:RequestWriter.cs
示例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
};
}
开发者ID:supernebula,项目名称:Plunder,代码行数:30,代码来源:FakePageAnalyzer.cs
示例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();
}
}
}
开发者ID:842549829,项目名称:Notify,代码行数:38,代码来源:HttpRequestUtility.cs
示例9: RequestReceivedEventArgs
public RequestReceivedEventArgs(Request request, Socket client, int byteCount)
{
this.request = request;
this.client = client;
this.byteCount = byteCount;
this.receiveTime = DateTime.Now;
}
开发者ID:joshs85,项目名称:Netduino-Aquarium-Controller,代码行数:8,代码来源:RequestReceivedEventArgs.cs
示例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'."));
}
开发者ID:darting,项目名称:MetricSystem,代码行数:9,代码来源:ServerTests.cs
示例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);
}
};
}
开发者ID:loudej,项目名称:taco,代码行数:56,代码来源:ProxyApp.cs
示例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));
}
开发者ID:darting,项目名称:MetricSystem,代码行数:11,代码来源:ListServers.cs
示例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);
}
}
开发者ID:vairam-svs,项目名称:oneget,代码行数:18,代码来源:WebDownloader.cs
示例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;
}
}
开发者ID:rlusian1,项目名称:CoAP.NET,代码行数:11,代码来源:HttpStack.cs
示例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;
}
开发者ID:artwhaley,项目名称:krpc,代码行数:11,代码来源:StreamManager.cs
示例16: OAuthAccess
public OAuthAccess(string consumerKey, string consumerSecret, string requestTokenURL, string accessTokenURL, string authorizeURL)
{
this.req = new Request();
this.rnd = new Random();
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
this.requestTokenURL = requestTokenURL;
this.accessTokenURL = accessTokenURL;
this.authorizeURL = authorizeURL;
}
开发者ID:deflis,项目名称:NekoVampire.Library,代码行数:11,代码来源:OAuthAccess.cs
示例17: Should_invoke_route_returned
public void Should_invoke_route_returned()
{
// Given
var request = new Request("GET", "/", "http");
// When
this.engine.HandleRequest(request);
// Then
A.CallTo(() => this.route.Invoke()).MustHaveHappened();
}
开发者ID:tt,项目名称:Nancy,代码行数:11,代码来源:NancyEngineFixture.cs
示例18: GetHeaders
public Dictionary<string, string> GetHeaders(Request request)
{
switch (Method)
{
case SignatureMethod.PLAINTEXT:
return GeneratePlainOAuthHeaders(request);
case SignatureMethod.HMACSHA1:
return GenerateHmacOAuthHeaders(request);
default:
return null;
}
}
开发者ID:milesdream,项目名称:Rester,代码行数:12,代码来源:OAuth1Authenticator.cs
示例19: ClosureCodeRequest
public ClosureCodeRequest(string apiUrl, CompilationLevel level, string jsContent)
{
apiUrl = string.IsNullOrEmpty(apiUrl) ? DefaultApiUrl : apiUrl;
request = new Request(apiUrl,
new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("compilation_level", level.ToString()),
new KeyValuePair<string, string>("js_code", jsContent),
new KeyValuePair<string, string>("output_format", "xml"),
new KeyValuePair<string, string>("output_info", "compiled_code"),
});
}
开发者ID:jozsurf,项目名称:combres,代码行数:12,代码来源:ClosureCodeRequest.cs
示例20: AddStream
public UInt32 AddStream (Request request, Type type)
{
CheckDisposed ();
var id = connection.KRPC ().AddStream (request);
lock (accessLock) {
if (!streamTypes.ContainsKey (id)) {
streamTypes [id] = type;
streamData [id] = connection.Invoke (request);
}
}
return id;
}
开发者ID:paperclip,项目名称:krpc,代码行数:12,代码来源:StreamManager.cs
注:本文中的System.Net.Request类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论