HttpGet.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Text;
  2. namespace IFramework.Net.Http
  3. {
  4. public class HttpGet
  5. {
  6. private HttpHeader header = null;
  7. public HttpGet(HttpHeader header)
  8. {
  9. this.header = header;
  10. }
  11. public HttpPayload GetDo(SegmentToken sToken)
  12. {
  13. return new HttpPayload()
  14. {
  15. Header = header,
  16. HttpUri = new HttpUri(header.RelativeUri),
  17. Token = sToken.sToken
  18. };
  19. }
  20. public string Response(string content, HttpStatusCode statusCode=HttpStatusCode.OK,
  21. string contentType="text/plain;charset=utf-8")
  22. {
  23. header.ContentType = contentType;
  24. string rspHeader = header.ToHeaderString(statusCode);
  25. StringBuilder builder = new StringBuilder(rspHeader);//header
  26. builder.Append(content);//body
  27. return builder.ToString();
  28. }
  29. public string Request()
  30. {
  31. return string.Empty;
  32. }
  33. }
  34. public enum HttpStatusCode
  35. {
  36. OK = 200,
  37. Moved = 301,
  38. NotModified = 304,
  39. Proxy = 305,
  40. Bad = 400,
  41. Unauthorized = 401,
  42. Forbidden = 403,
  43. NotFound = 404,
  44. NotAllowed = 405,
  45. TooLarge = 413,
  46. InternalError = 500,
  47. BadGateway = 502,
  48. Unavailable = 503,
  49. NotSupported = 505
  50. }
  51. }