本文整理汇总了C#中HttpConnection类的典型用法代码示例。如果您正苦于以下问题:C# HttpConnection类的具体用法?C# HttpConnection怎么用?C# HttpConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpConnection类属于命名空间,在下文中一共展示了HttpConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApiClient
protected ApiClient(ApiKeyConnection connection)
{
Ensure.ArgumentNotNull(connection, nameof(connection));
ApiKeyConnection = connection;
HttpConnection = new HttpConnection(ApiKeyConnection);
}
示例2: GetConnection
IObservable<HttpConnection> GetConnection(Uri uri)
{
if(m_connection!= null
&& m_connection.Uri.Host==uri.Host
&& m_connection.Uri.Port==uri.Port
&& m_connection.IsConnected
)
{
return Observable.Return(m_connection)
.Do(x =>
{
Console.WriteLine("<KeepAlive>");
})
;
}
else
{
return HttpConnection.Create(uri).Connect()
.Do(x => {
m_connection = x;
Console.WriteLine(x);
})
;
}
}
示例3: SendMessageSendsAndReceivesAMessage
public void SendMessageSendsAndReceivesAMessage()
{
var action = "DoSomething";
var request = new ServerRequest
{
ServerName = "TestServer"
};
var url = "http://somewhere/";
var factory = new TestClientFactory((u, a, d) =>
{
Assert.AreEqual(url + "server/TestServer/RawXmlMessage.aspx", u.AbsoluteUri);
Assert.AreEqual("POST", a);
Assert.AreEqual(action, d["action"]);
Assert.AreEqual(request.ToString(), d["message"]);
var theResponse = new Response
{
RequestIdentifier = request.Identifier
};
return Encoding.UTF8.GetBytes(theResponse.ToString());
});
var connection = new HttpConnection(new Uri(url), factory);
var response = connection.SendMessage(action, request);
Assert.IsInstanceOf<Response>(response);
Assert.AreEqual(request.Identifier, response.RequestIdentifier);
}
示例4: HttpListenerContext
internal HttpListenerContext(HttpConnection cnc, ILogger logger)
{
this.cnc = cnc;
_logger = logger;
request = new HttpListenerRequest(this);
response = new HttpListenerResponse(this, _logger);
}
示例5: Setup
public void Setup()
{
requestedUrl.Clear();
partialData = false;
int i;
for (i = 0; i < 1000; i++)
{
try
{
listener = new HttpListener();
listener.Prefixes.Add(string.Format(listenerURL, i));
listener.Start();
break;
}
catch
{
}
}
listener.BeginGetContext(GotContext, null);
rig = TestRig.CreateMultiFile();
connection = new HttpConnection(new Uri(string.Format(listenerURL, i)));
connection.Manager = rig.Manager;
id = new PeerId(new Peer("this is my id", connection.Uri), rig.Manager);
id.Connection = connection;
id.IsChoking = false;
id.AmInterested = true;
id.BitField.SetAll(true);
id.MaxPendingRequests = numberOfPieces;
requests = rig.Manager.PieceManager.Picker.PickPiece(id, new List<PeerId>(), numberOfPieces);
}
示例6: HttpListenerContext
internal HttpListenerContext (HttpConnection cnc)
{
this.cnc = cnc;
err_status = 400;
request = new HttpListenerRequest (this);
response = new HttpListenerResponse (this);
}
示例7: RemoveConnection
public void RemoveConnection(HttpConnection connection)
{
lock (this._requests)
{
this._requests.Remove(connection);
}
}
示例8: ExecuteTest
public void ExecuteTest()
{
HttpConnection target = new HttpConnection();
HttpWebRequest httpRequest = GetHttpWebRequest();
string actual = target.Execute(payLoad, httpRequest);
Assert.IsNotNull(actual);
}
示例9: Client
public Client(HttpConnection connection)
{
_nodeName = Environment.GetEnvironmentVariable("CONSUL_CLIENT_NODE_NAME") ?? "undefined node";
_serviceName = Environment.GetEnvironmentVariable("CONSUL_CLIENT_SERVICE_NAME") ?? "undefined service";
_datacenterName = Environment.GetEnvironmentVariable("CONSUL_CLIENT_DATACENTER_NAME") ?? "dc1";
_catalog = new Catalog(connection);
}
示例10: AspWorkerRequest
// private bool _headersSent;
/// <summary>
/// Initializes a new instance of the AspWorkerRequest class
/// </summary>
/// <param name="connection"></param>
/// <param name="request"></param>
public AspWorkerRequest(AspHost aspHost, HttpConnection connection, HttpRequest request) : base(string.Empty, string.Empty, null)
{
_aspHost = aspHost;
_connection = connection;
_request = request;
_response = new HttpResponse(new OkStatus());
this.ParsePathInfo();
}
示例11: AddressBookItemConnectionManager
/// <summary>
/// Initializes a new instance of the AddressBookItemConnectionManager class
/// </summary>
/// <param name="item">The address book item that defines the remote host to connect to</param>
/// <param name="connection">The Tcp connection that will be used throughout the lifetime of the connection</param>
public AddressBookItemConnectionManager(AddressBookItem item, HttpConnection connection)
{
if (item == null)
throw new ArgumentNullException("item");
if (connection == null)
throw new ArgumentNullException("connection");
_propertyBag = new Hashtable();
_item = item;
_connection = connection;
_connection.Opened += new HttpConnectionEventHandler(OnInternalConnectionOpened);
_connection.Closed += new HttpConnectionEventHandler(OnInternalConnectionClosed);
_connection.Exception += new ExceptionEventHandler(OnInternalConnectionException);
}
示例12: NanoHttpRequest
public NanoHttpRequest(HttpConnection conn, string request)
{
Connection = conn;
if (string.IsNullOrEmpty(request))
{
Invalid = true;
return;
}
var fls = request.Split(new char[]{ ' ' }, 3);
if (fls.Length < 2)
{
Invalid = true;
return;
}
Method = fls[0];
Address = fls[1];
//if (Method == "POST")
{
var heco = request.Split(new string[]{ "\r\n\r\n" }, 2, StringSplitOptions.None);
if (heco.Length < 2)
{
Invalid = true;
return;
}
var he = heco[0];
var co = heco[1];
Content = co;
var lines = he.Split(new string[]{ "\r\n", "\n" }, StringSplitOptions.None);
for (int i = 1; i < lines.Length; i++)
{
var hl = lines[i].Split(new String[]{": "}, 2, StringSplitOptions.None);
if (hl.Length < 2) continue;
Headers[hl[0]] = hl[1];
}
}
}
示例13: RequestTimeout
public void RequestTimeout(HttpConnection connection)
{
var param = connection.Param;
int msgId = param.Get("MsgId").ToInt();
int actionId = param.Get("ActionId").ToInt();
int errorCode = LanguageHelper.GetLang().ErrorCode;
string errorMsg = LanguageHelper.GetLang().RequestTimeout;
var head = new MessageHead(msgId, actionId, "st", errorCode, errorMsg);
head.HasGzip = true;
var ms = new MessageStructure();
ms.WriteBuffer(head);
byte[] data = ms.ReadBuffer();
string remoteAddress = connection.Context.Request.RemoteEndPoint.Address.ToString();
string successMsg = string.Format("{0}>>发送超时到{1} {2}字节!",
DateTime.Now.ToString("HH:mm:ss:ms"), remoteAddress, data.Length);
Console.WriteLine(successMsg);
OnResponseCompleted(connection, data);
}
示例14: Process
private void Process(HttpConnection connection, NanoHttpRequest request)
{
if (request.Address == "/")
{
connection.Response(_root.Handle(request));
return;
}
var endpoint = request.Address.Split(new char[]{'/'}, StringSplitOptions.RemoveEmptyEntries)[0];
if (_handlers.ContainsKey(endpoint))
{
connection.Response(_handlers[endpoint].Handle(request));
}
else
{
connection.Response(new ErrorHandler(StatusCode.BadRequest, "Unknown endpoint: " + endpoint).Handle(request));
}
}
示例15: Run
protected override void Run()
{
this._listener.Start();
while (true)
{
try
{
TcpClient client = this._listener.AcceptTcpClient();
HttpConnection connection = new HttpConnection(this, client);
lock (this._requests)
{
this._requests.Add(connection);
}
connection.Start();
}
catch {
}
}
}