本文整理汇总了C#中System.Net.Response类的典型用法代码示例。如果您正苦于以下问题:C# Response类的具体用法?C# Response怎么用?C# Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于System.Net命名空间,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApiException
protected ApiException(string message, Response response)
: base(message)
{
ResponseBody = response.Body;
Headers = response.Headers;
StatusCode = response.StatusCode;
}
示例2: Run
public void Run()
{
try
{
while (true)
{
Socket client = server.Accept();
Response response = new Response(this, client);
Thread thread = new Thread(response.Run);
thread.Start();
}
}
catch (Exception)
{
}
finally
{
try
{
server.Close();
}
catch (Exception)
{
}
}
}
示例3: CreateAsync
/// <summary>
/// Create the room
/// </summary>
/// <param name="name">The name.</param>
/// <param name="owner">The owner.</param>
/// <param name="privacy">The privacy.</param>
/// <param name="guestAccess">if set to <c>true</c> [guest access].</param>
/// <returns>Task<IResponse<Entity>>.</returns>
/// <exception cref="System.NotImplementedException"></exception>
public async Task<IResponse<bool>> CreateAsync(string name, string owner, RoomPrivacy privacy = RoomPrivacy.Public, bool guestAccess = false)
{
Validate.Length(name, 100, "Room Name");
Validate.Mention(owner, "Owner");
var room = new CreateRoom
{
Name = name,
OwnerUserId = owner,
GuestAccess = guestAccess,
Privacy = privacy
};
var json = JsonConvert.SerializeObject(room, Formatting.None, _jsonSettings);
var payload = new StringContent(json, Encoding.UTF8, "application/json");
var result = await ApiConnection.Client.PostAsync("room", payload);
var rawResponse = await result.Content.ReadAsStringAsync();
var response = new Response<bool>(true)
{
Code = result.StatusCode,
Body = rawResponse,
ContentType = result.Content.Headers.ContentType.MediaType
};
return response;
}
示例4: ValidateProductResponse
protected void ValidateProductResponse(Response<Product> result)
{
Assert.IsNotNull(result, "Expected a result");
Assert.IsNotNull(result.StatusCode, "Expected a status code");
Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a 200 response");
Assert.IsNotNull(result.Result, "Expected a result");
Assert.IsNull(result.Error, "Expected no error");
Assert.IsFalse(string.IsNullOrEmpty(result.Result.Id), "Expected Id to be populated");
Assert.IsFalse(string.IsNullOrEmpty(result.Result.Name), "Expected Name to be populated");
Assert.AreNotEqual(Category.Unknown, result.Result.Category, "Expected Category to be set");
if (result.Result.Category == Category.Album)
{
Assert.That(result.Result.Tracks.Count, Is.AtLeast(1));
foreach (var track in result.Result.Tracks)
{
Assert.IsFalse(string.IsNullOrEmpty(track.Id), "Expected trackId to be populated");
Assert.IsFalse(string.IsNullOrEmpty(track.Name), "Expected trackName to be populated");
Assert.AreNotEqual(Category.Unknown, track.Category, "Expected trackCategory to be set");
}
}
}
示例5: Get
public HttpResponseMessage Get(string Method, string Ver = null, string Device = null, string Sid = null, string Md5 = null, int channel_id = 0, int start = 0, int end = 0, string group_id = null, string filter = null, int recording_id = 0, string name = null, int channel = 0, int time_t = 0, int duration = 0)
{
Logger.ServiceILog("Service Request: {0}, {1}", Method, Request.RequestUri.ToString());
object response = new Response() { ErrorCode = 0, ErrorMessage = "Unknown method." };
try
{
switch ((Method ?? "").ToLower())
{
case "session.initiate": response = Session_Initiate(Ver, Device); break;
case "session.login": response = Session_Login(Sid, Md5); break;
case "channel.icon": response = Channel_Icon(channel_id); break;
default:
{
var config = new Models.Configuration();
int userOid = 0;
if (config.EnableUserSupport) /* ensure a user is found if users are enabled */
{
if (!String.IsNullOrWhiteSpace(Sid) && SessionUserOids.ContainsKey(Sid))
userOid = SessionUserOids[Sid];
else
throw new UnauthorizedAccessException();
}
switch ((Method ?? "").ToLower())
{
case "setting.list": response = Setting_List(); break;
case "channel.listings": response = Channel_Listings(userOid, channel_id, start, end); break;
case "channel.list": response = Channel_List(userOid, group_id); break;
case "channel.groups": response = Channel_Groups(userOid); break;
case "recording.list": response = Recording_List(userOid, filter); break;
case "recording.delete": response = Recording_Delete(userOid, recording_id); break;
case "recording.save": response = Recording_Save(userOid, name, channel, time_t, duration); break;
}
}
break;
}
}
catch (InvalidSessionException)
{
response = new Response()
{
ErrorCode = 8,
ErrorMessage = "Invalid Session",
Stat = Response.ResponseStat.fail /* NOTE: this is a "fail" response */
};
}
catch (ChannelNotFoundException)
{
response = new Response()
{
ErrorCode = 5,
ErrorMessage = "Channel not found",
Stat = Response.ResponseStat.failed /* NOTE: this is a "fail" response */
};
}
if (response is Response)
return new HttpResponseMessage() { Content = new StringContent(response.ToString(), System.Text.Encoding.UTF8, "application/xml") };
else if (response == null)
return new HttpResponseMessage(HttpStatusCode.NotFound);
return response as HttpResponseMessage;
}
示例6: Should_set_properties_when_creating_oauth_exception
public void Should_set_properties_when_creating_oauth_exception()
{
var dummyResponse = new Response(HttpStatusCode.BadRequest,"Test Body");
var result = new OAuthException(dummyResponse);
Assert.That(result.ResponseBody, Is.EqualTo(dummyResponse.Body));
Assert.That(result.StatusCode, Is.EqualTo(dummyResponse.StatusCode));
}
示例7: Test
/// <summary>
/// 测试
/// </summary>
public static void Test()
{
MemoryStream stream = new MemoryStream();
Response response = new Response();
response.iii = 888;
response.i64 = Int64.MaxValue / 2;
response.time = DateTime.Now;
response.Str = "大石头";
response.Public = new IPEndPoint(IPAddress.Loopback, 1234);
response.Private = new List<IPEndPoint>();
response.Private.Add(response.Public);
response.Private.Add(new IPEndPoint(IPAddress.Broadcast, 2));
response.Private.Add(new IPEndPoint(IPAddress.IPv6Any, 33));
ProtocolFormatter pf = new ProtocolFormatter();
pf.Head.Config.NoHead = true;
pf.Head.Config.EncodeInt = true;
pf.Serialize(stream, response);
Byte[] buffer = stream.ToArray();
Console.WriteLine("[{0}] {1}", buffer.Length, BitConverter.ToString(buffer).Replace("-", " "));
File.WriteAllBytes("Protocol.dat", buffer);
stream = new MemoryStream(buffer);
pf = new ProtocolFormatter();
pf.Head.Config.NoHead = true;
pf.Head.Config.EncodeInt = true;
response = new Response();
pf.Deserialize(stream, response);
Console.WriteLine(response.Str);
}
示例8: GetEmployees
public HttpResponseMessage GetEmployees(long id, [FromUri]long[] loc = null)
{
if (id <= 0)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
IEnumerable<Employee> output = null;
IEnumerable<EmployeeModel> employees = null;
if (!loc.IsNullOrEmpty())
{
JoinTableRepository<EmployeeModel, SkillsetModel> repository = new JoinTableRepository<EmployeeModel, SkillsetModel>();
IEnumerable<string> employeeIds = repository.GetLeft(id).Select(x => x.EmpId).ToList();
CommonRepository<MToMTableModel<EmployeeModel, LocationModel>> repositoryEmpLoc = new CommonRepository<MToMTableModel<EmployeeModel, LocationModel>>();
employees = repositoryEmpLoc.GetBySpecification(new Specification<MToMTableModel<EmployeeModel, LocationModel>>(x => x.LeftItem.IsActive == true && x.RightItem.IsActive == true && employeeIds.Contains(x.LeftItem.EmpId) && loc.Contains(x.RightItem.Id))).Select(x => x.LeftItem);
output = AutoMapper.MapCollection<EmployeeModel, Employee>(employees);
}
else
{
TryGetItemEmployees(id, out output);
}
if (output.IsNullOrEmpty())
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}
Response<IEnumerable<Employee>> results = new Response<IEnumerable<Employee>>(output);
return Request.CreateResponse(HttpStatusCode.OK, results);
}
示例9: ApiResponseException
protected ApiResponseException(string message, Exception innerException, Response response)
: base(message, innerException)
{
ResponseBody = response.Body;
Headers = response.Headers;
StatusCode = response.StatusCode;
}
示例10: DeleteVideo
public Response<VideoView> DeleteVideo(Int64 Id)
{
if (this.videoService.DeleteVideo(Id) == true)
{
var response = new Response<VideoView> { Model = { } };
response.Messages.Add(new Message
{
MessageType = MessageType.Success,
Value = "Video Has Been Deleted"
});
return response;
}
else
{
var response = new Response<VideoView> { Model = { } };
response.Messages.Add(new Message
{
MessageType = MessageType.Warning,
Value = "Video Has Reference(s) In Renting"
});
return response;
}
}
示例11: 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>"
);
}
示例12: DeleteUser
public Response<UserView> DeleteUser(Int64 Id)
{
if (this._userService.DeleteUser(Id) == true)
{
//// build response
var response = new Response<UserView> { Model = { } };
response.Messages.Add(new Message
{
MessageType = MessageType.Success,
Value = "User Has Been Deleted"
});
return response;
}
else
{
//// build response
var response = new Response<UserView> { Model = { } };
response.Messages.Add(new Message
{
MessageType = MessageType.Warning,
Value = "User Has Reference(s) In Renting"
});
return response;
}
}
示例13: AddHttpException
internal void AddHttpException(Exception ex, int count = 1)
{
for (int i = 0; i < count; i++)
{
var response = new Response() { Exception = ex };
this.responses.Add(response);
}
}
示例14: AddHttpResponse
internal void AddHttpResponse(IHttpResponseMessageAbstraction responseMessage, int count = 1)
{
for (int i = 0; i < count; i++)
{
var response = new Response() { ResponseMessage = responseMessage };
this.responses.Add(response);
}
}
示例15: DefaultResponse
public void DefaultResponse()
{
var response = new Response();
response.Body.Should().BeNull();
response.ContentType.Should().BeNull();
response.Headers.Should().BeEmpty();
response.StatusCode.Should().Be(default(HttpStatusCode));
}