HttpPost.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Text;
  2. using System.IO;
  3. namespace IFramework.Net.Http
  4. {
  5. public class HttpPost
  6. {
  7. private HttpHeader header = null;
  8. public HttpPost(HttpHeader header)
  9. {
  10. this.header = header;
  11. }
  12. public HttpPayload GetDo(SegmentToken sToken)
  13. {
  14. var paylaod = new HttpPayload()
  15. {
  16. Header = header,
  17. HttpUri = new HttpUri(header.RelativeUri),
  18. Token = sToken.sToken
  19. };
  20. if (header.ContentLength > 0)
  21. {
  22. SegmentOffset seg = sToken.Data;
  23. paylaod.stream = new MemoryStream(seg.buffer,
  24. seg.offset + (int)header.StreamPosition,
  25. (int)header.ContentLength);
  26. }
  27. return paylaod;
  28. }
  29. public string Response(string content, HttpStatusCode statusCode=HttpStatusCode.OK,
  30. string contentType = "text/plain;charset=utf-8")
  31. {
  32. header.ContentType = contentType;
  33. string rspHeader = header.ToHeaderString(statusCode);
  34. StringBuilder builder = new StringBuilder(rspHeader);//header
  35. builder.Append(content);//body
  36. return builder.ToString();
  37. }
  38. public string Request()
  39. {
  40. return string.Empty;
  41. }
  42. }
  43. }