本文整理汇总了C#中System.Net.Response类的典型用法代码示例。如果您正苦于以下问题:C# Response类的具体用法?C# Response怎么用?C# Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于System.Net命名空间,在下文中一共展示了Response类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ApiException
protected ApiException(string message, Response response)
: base(message)
{
ResponseBody = response.Body;
Headers = response.Headers;
StatusCode = response.StatusCode;
}
开发者ID:knocte,项目名称:SevenDigital.Api.Wrapper,代码行数:7,代码来源:ApiException.cs
示例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)
{
}
}
}
开发者ID:niwakazoider,项目名称:QuitYp,代码行数:29,代码来源:QuitServer.cs
示例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;
}
开发者ID:aolszowka,项目名称:hipchat.net,代码行数:36,代码来源:RoomsClient.cs
示例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");
}
}
}
开发者ID:hoangtanduy247,项目名称:wp-api-client,代码行数:25,代码来源:ProductTestBase.cs
示例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;
}
开发者ID:JonnyCam,项目名称:NextPvrWebConsole,代码行数:60,代码来源:ServiceController.cs
示例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));
}
开发者ID:raoulmillais,项目名称:SevenDigital.Api.Wrapper,代码行数:7,代码来源:ExceptionFactoryTests.cs
示例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);
}
开发者ID:windygu,项目名称:asxinyunet,代码行数:35,代码来源:ProtocolTest.cs
示例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);
}
开发者ID:kvramireddy,项目名称:First,代码行数:30,代码来源:SkillsetController.cs
示例9: ApiResponseException
protected ApiResponseException(string message, Exception innerException, Response response)
: base(message, innerException)
{
ResponseBody = response.Body;
Headers = response.Headers;
StatusCode = response.StatusCode;
}
开发者ID:raoulmillais,项目名称:SevenDigital.Api.Wrapper,代码行数:7,代码来源:ApiResponseException.cs
示例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;
}
}
开发者ID:KukuhUtama,项目名称:EntityFirstApp,代码行数:25,代码来源:VideoController.cs
示例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>"
);
}
开发者ID:wmeyer,项目名称:SharpCGI,代码行数:32,代码来源:Program.cs
示例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;
}
}
开发者ID:KukuhUtama,项目名称:EntityFirstApp,代码行数:27,代码来源:UserController.cs
示例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);
}
}
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:8,代码来源:HttpRetryTests.cs
示例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);
}
}
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:8,代码来源:HttpRetryTests.cs
示例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));
}
开发者ID:mattjamieson,项目名称:tinyhttp,代码行数:8,代码来源:ResponseTest.cs
示例16: Should_create_invalid_resource_exception_when_creating_non_api_error_exception_with_2xxx_code
public void Should_create_invalid_resource_exception_when_creating_non_api_error_exception_with_2xxx_code()
{
var dummyResponse = new Response(HttpStatusCode.BadRequest, "Test Body");
var error = new Error { Code = 2001 };
var result = ExceptionFactory.CreateApiErrorException(error, dummyResponse);
Assert.That(result, Is.TypeOf<InvalidResourceException>());
}
开发者ID:raoulmillais,项目名称:SevenDigital.Api.Wrapper,代码行数:8,代码来源:ExceptionFactoryTests.cs
示例17: Login
public Response<RespLogin> Login(UserModel objUserModel)
{
List<RespLogin> objResp = new List<RespLogin>();
Response<RespLogin> response = new Response<RespLogin>();
try
{
objDBMethod = new DBMethod();
if (CheckRequestIsvalidornot(this.Request))
{
objResp.Add(objDBMethod.Login(objUserModel));
switch (objResp[0].restKey)
{
case "0":
response.Create(false, Messages.WebError, Messages.AppVersion, objResp);
break;
case "1":
response.Create(true, Messages.FormatMessage(Messages.Success, "Logged in "), Messages.AppVersion, objResp);
break;
case "2":
response.Create(false, Messages.NotAllowedUser, Messages.AppVersion, objResp);
break;
case "3":
response.Create(false, Messages.InvalidPassword, Messages.AppVersion, objResp);
break;
case "4":
response.Create(false, Messages.EmailVerify, Messages.AppVersion, objResp);
break;
case "5":
response.Create(true, Messages.AccountCreated, Messages.AppVersion, objResp);
break;
case "6":
response.Create(false, "Sorry!!! we were unable to fetch your email please change your Facebook settings for email.", Messages.AppVersion, objResp);
break;
default:
response.Create(false, Messages.FormatMessage(Messages.InvalidReq), Messages.AppVersion, objResp);
break;
}
}
else
{
response.Create(false, Messages.FormatMessage(Messages.InvalidReq), Messages.AppVersion, objResp);
}
}
catch (Exception ex)
{
object session = new JavaScriptSerializer().Serialize(objUserModel);
LogManager.Error("Error occured while Processing Webservice request :{0}", ex, session, ex.Message);
response.Create(false, Messages.FormatMessage(Messages.ErrorOccure), Messages.AppVersion, objResp);
}
finally
{
}
return response;
}
开发者ID:rjdeveloper,项目名称:bigdecimalweb,代码行数:58,代码来源:WebServiceV2Controller.cs
示例18: ValidateASuccessfulResponse
public void ValidateASuccessfulResponse()
{
const string SuccessfulResponse = "joy";
Response<string> response = new Response<string>(HttpStatusCode.OK, SuccessfulResponse);
Assert.IsNotNull(response, "Expected a new Response");
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Expected the same status code");
Assert.AreEqual(SuccessfulResponse, response.Result, "Expected the same result");
Assert.IsNull(response.Error, "Expected no error");
}
开发者ID:Tinytoot,项目名称:wp-api-client,代码行数:9,代码来源:ResponseTests.cs
示例19: ValidateAFailedResponse
public void ValidateAFailedResponse()
{
Exception e = new ApiCredentialsRequiredException();
Response<string> response = new Response<string>(null, e);
Assert.IsNotNull(response, "Expected a new Response");
Assert.IsNull(response.StatusCode, "Expected no status code");
Assert.AreEqual(e, response.Error, "Expected the same error");
Assert.IsNull(response.Result, "Expected no result");
}
开发者ID:Tinytoot,项目名称:wp-api-client,代码行数:9,代码来源:ResponseTests.cs
示例20: ServerResponse
/// <summary>
/// Initializes a new instance of the <see cref="ServerResponse"/> class.
/// </summary>
/// <param name="responseToReturn">A <see cref="Response"/> object to be sent to the remote client.</param>
/// <param name="status">An <see cref="HttpStatusCode"/> value to set the status code of the HTTP response.</param>
internal ServerResponse(Response responseToReturn, HttpStatusCode status)
{
this.returnedResponse = responseToReturn;
this.statusCode = status;
if (this.statusCode >= HttpStatusCode.BadRequest && this.statusCode < HttpStatusCode.InternalServerError)
{
this.contentType = "text/plain";
}
}
开发者ID:jimevans,项目名称:strontium,代码行数:14,代码来源:ServerResponse.cs
注:本文中的System.Net.Response类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论