本文整理汇总了C#中HTTPRequest.Send方法的典型用法代码示例。如果您正苦于以下问题:C# HTTPRequest.Send方法的具体用法?C# HTTPRequest.Send怎么用?C# HTTPRequest.Send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPRequest
的用法示例。
在下文中一共展示了HTTPRequest.Send方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartAuthentication
public void StartAuthentication()
{
AuthRequest = new HTTPRequest(AuthUri, HTTPMethods.Post, OnAuthRequestFinished);
// Setup the form
AuthRequest.AddField("userName", UserName);
AuthRequest.AddField("Password", Password); // not used in the sample
AuthRequest.AddField("roles", UserRoles);
AuthRequest.Send();
}
示例2: Connect
/// <summary>
/// Polling transport specific connection logic. It's a regular GET request to the /connect path.
/// </summary>
public override void Connect()
{
HTTPManager.Logger.Information("Transport - " + this.Name, "Sending Open Request");
// Skip the Connecting state if we are reconnecting. If the connect succeeds, we will set the Started state directly
if (this.State != TransportStates.Reconnecting)
this.State = TransportStates.Connecting;
RequestTypes requestType = this.State == TransportStates.Reconnecting ? RequestTypes.Reconnect : RequestTypes.Connect;
var request = new HTTPRequest(Connection.BuildUri(requestType, this), HTTPMethods.Get, true, true, OnConnectRequestFinished);
Connection.PrepareRequest(request, requestType);
request.Send();
}
示例3: Start
/// <summary>
/// Internal function, this will start a regular GET request to the server to receive the handshake data.
/// </summary>
internal void Start()
{
if (HandshakeRequest != null)
return;
HandshakeRequest = new HTTPRequest(new Uri(string.Format("{0}?EIO={1}&transport=polling&t={2}-{3}{4}&b64=true",
Manager.Uri.ToString(),
SocketManager.MinProtocolVersion,
Manager.Timestamp,
Manager.RequestCounter++,
Manager.Options.BuildQueryParams())),
OnHandshakeCallback);
// Don't even try to cache it
HandshakeRequest.DisableCache = true;
HandshakeRequest.Send();
HTTPManager.Logger.Information("HandshakeData", "Handshake request sent");
}
示例4: Open
public void Open()
{
// First request after handshake
var request = new HTTPRequest(new Uri(string.Format("{0}?EIO={1}&transport=polling&t={2}-{3}&sid={4}{5}&b64=true",
Manager.Uri.ToString(),
SocketManager.MinProtocolVersion,
Manager.Timestamp.ToString(),
Manager.RequestCounter++.ToString(),
Manager.Handshake.Sid,
!Manager.Options.QueryParamsOnlyForHandshake ? Manager.Options.BuildQueryParams() : string.Empty)),
OnRequestFinished);
// Don't even try to cache it
request.DisableCache = true;
request.DisableRetry = true;
request.Send();
State = TransportStates.Opening;
}
示例5: Send
public void Send(System.Collections.Generic.List<Packet> packets)
{
if (State != TransportStates.Open)
throw new Exception("Transport is not in Open state!");
if (IsRequestInProgress)
throw new Exception("Sending packets are still in progress!");
byte[] buffer = null;
try
{
buffer = packets[0].EncodeBinary();
for (int i = 1; i < packets.Count; ++i)
{
byte[] tmpBuffer = packets[i].EncodeBinary();
Array.Resize(ref buffer, buffer.Length + tmpBuffer.Length);
Array.Copy(tmpBuffer, 0, buffer, buffer.Length - tmpBuffer.Length, tmpBuffer.Length);
}
packets.Clear();
}
catch (Exception ex)
{
(Manager as IManager).EmitError(SocketIOErrors.Internal, ex.Message + " " + ex.StackTrace);
return;
}
LastRequest = new HTTPRequest(new Uri(string.Format("{0}?EIO={1}&transport=polling&t={2}-{3}&sid={4}{5}&b64=true",
Manager.Uri.ToString(),
SocketManager.MinProtocolVersion,
Manager.Timestamp.ToString(),
Manager.RequestCounter++.ToString(),
Manager.Handshake.Sid,
!Manager.Options.QueryParamsOnlyForHandshake ? Manager.Options.BuildQueryParams() : string.Empty)),
HTTPMethods.Post,
OnRequestFinished);
// Don't even try to cache it
LastRequest.DisableCache = true;
LastRequest.SetHeader("Content-Type", "application/octet-stream");
LastRequest.RawData = buffer;
LastRequest.Send();
}
示例6: Poll
public void Poll()
{
if (PollRequest != null || State == TransportStates.Paused)
return;
PollRequest = new HTTPRequest(new Uri(string.Format("{0}?EIO={1}&transport=polling&t={2}-{3}&sid={4}{5}&b64=true",
Manager.Uri.ToString(),
SocketManager.MinProtocolVersion,
Manager.Timestamp.ToString(),
Manager.RequestCounter++.ToString(),
Manager.Handshake.Sid,
!Manager.Options.QueryParamsOnlyForHandshake ? Manager.Options.BuildQueryParams() : string.Empty)),
HTTPMethods.Get,
OnPollRequestFinished);
// Don't even try to cache it
PollRequest.DisableCache = true;
PollRequest.DisableRetry = true;
PollRequest.Send();
}
示例7: Ping
/// <summary>
/// Sends a Ping request to the SignalR server.
/// </summary>
private void Ping()
{
HTTPManager.Logger.Information("SignalR Connection", "Sending Ping request.");
PingRequest = new HTTPRequest((this as IConnection).BuildUri(RequestTypes.Ping), OnPingRequestFinished);
PingRequest.ConnectTimeout = PingInterval;
PingRequest.Send();
LastPingSentAt = DateTime.UtcNow;
}
示例8: OnAbortRequestFinished
private void OnAbortRequestFinished(HTTPRequest req, HTTPResponse resp)
{
switch (req.State)
{
case HTTPRequestStates.Finished:
if (resp.IsSuccess)
{
HTTPManager.Logger.Information("Transport - " + this.Name, "Abort - Returned: " + resp.DataAsText);
if (this.State == TransportStates.Closing)
AbortFinished();
}
else
{
HTTPManager.Logger.Warning("Transport - " + this.Name, string.Format("Abort - Handshake request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2} Uri: {3}",
resp.StatusCode,
resp.Message,
resp.DataAsText,
req.CurrentUri));
// try again
goto default;
}
break;
default:
HTTPManager.Logger.Information("Transport - " + this.Name, "Abort request state: " + req.State.ToString());
// The request may not reached the server. Try it again.
int retryCount = (int)req.Tag;
if (retryCount++ < MaxRetryCount)
{
req.Tag = retryCount;
req.Send();
}
else
Connection.Error("Failed to send Abort request!");
break;
}
}
示例9: Abort
/// <summary>
/// Will abort the transport. In SignalR 'Abort'ing is a graceful process, while 'Close'ing is a hard-abortion...
/// </summary>
public virtual void Abort()
{
if (this.State != TransportStates.Started)
return;
this.State = TransportStates.Closing;
var request = new HTTPRequest(Connection.BuildUri(RequestTypes.Abort, this), HTTPMethods.Get, true, true, OnAbortRequestFinished);
// Retry counter
request.Tag = 0;
request.DisableRetry = true;
Connection.PrepareRequest(request, RequestTypes.Abort);
request.Send();
}
示例10: OnStartRequestFinished
private void OnStartRequestFinished(HTTPRequest req, HTTPResponse resp)
{
switch (req.State)
{
case HTTPRequestStates.Finished:
if (resp.IsSuccess)
{
HTTPManager.Logger.Information("Transport - " + this.Name, "Start - Returned: " + resp.DataAsText);
string response = Connection.ParseResponse(resp.DataAsText);
if (response != "started")
{
Connection.Error(string.Format("Expected 'started' response, but '{0}' found!", response));
return;
}
// The transport and the signalr protocol now started
this.State = TransportStates.Started;
Started();
Connection.TransportStarted();
return;
}
else
HTTPManager.Logger.Warning("Transport - " + this.Name, string.Format("Start - request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2} Uri: {3}",
resp.StatusCode,
resp.Message,
resp.DataAsText,
req.CurrentUri));
goto default;
default:
HTTPManager.Logger.Information("Transport - " + this.Name, "Start request state: " + req.State.ToString());
// The request may not reached the server. Try it again.
int retryCount = (int)req.Tag;
if (retryCount++ < MaxRetryCount)
{
req.Tag = retryCount;
req.Send();
}
else
Connection.Error("Failed to send Start request.");
break;
}
}
示例11: Start
/// <summary>
/// Sends out the /start request to the server.
/// </summary>
protected void Start()
{
HTTPManager.Logger.Information("Transport - " + this.Name, "Sending Start Request");
this.State = TransportStates.Starting;
if (this.Connection.Protocol > ProtocolVersions.Protocol_2_0)
{
var request = new HTTPRequest(Connection.BuildUri(RequestTypes.Start, this), HTTPMethods.Get, true, true, OnStartRequestFinished);
request.Tag = 0;
request.DisableRetry = true;
request.Timeout = Connection.NegotiationResult.ConnectionTimeout + TimeSpan.FromSeconds(10);
Connection.PrepareRequest(request, RequestTypes.Start);
request.Send();
}
else
{
// The transport and the signalr protocol now started
this.State = TransportStates.Started;
Started();
Connection.TransportStarted();
}
}
示例12: Start
/// <summary>
/// Start to get the negotiation data.
/// </summary>
public void Start()
{
NegotiationRequest = new HTTPRequest(Connection.BuildUri(RequestTypes.Negotiate), HTTPMethods.Get, true, true, OnNegotiationRequestFinished);
Connection.PrepareRequest(NegotiationRequest, RequestTypes.Negotiate);
NegotiationRequest.Send();
HTTPManager.Logger.Information("NegotiationData", "Negotiation request sent");
}
示例13: Poll
/// <summary>
/// Polling transport speficic function. Sends a GET request to the /poll path to receive messages.
/// </summary>
private void Poll()
{
pollRequest = new HTTPRequest(Connection.BuildUri(RequestTypes.Poll, this), HTTPMethods.Get, true, true, OnPollRequestFinished);
Connection.PrepareRequest(pollRequest, RequestTypes.Poll);
pollRequest.Timeout = this.PollTimeout;
pollRequest.Send();
}
示例14: Start
/// <summary>
/// Sends out the /start request to the server.
/// </summary>
protected void Start()
{
HTTPManager.Logger.Information("Transport - " + this.Name, "Sending Start Request");
this.State = TransportStates.Starting;
var request = new HTTPRequest(Connection.BuildUri(RequestTypes.Start, this), HTTPMethods.Get, true, true, OnStartRequestFinished);
request.Tag = 0;
request.DisableRetry = true;
request.Timeout = Connection.NegotiationResult.ConnectionTimeout + TimeSpan.FromSeconds(10);
Connection.PrepareRequest(request, RequestTypes.Start);
request.Send();
}