コード例 #1
0
 /// <summary>
 /// ��������
 /// </summary>
 public HttpWebRequest CreateHttpRequest(Request request)
 {
     var webrequest = (HttpWebRequest)WebRequest.Create(request.Url);
     webrequest.Accept = Accept;
     webrequest.UserAgent = UserAgent;
     webrequest.Timeout = request.GetTimeoutMs();
     if (Cookie != null)
     {
         webrequest.CookieContainer = Cookie;
     }
     switch (request.Methods)
     {
         case Request.Method.DEPRECATED_GET_OR_POST:
             {
                 if (request.GetPostBody() != null)
                 {
                     webrequest.Method = HttpMethod.POST;
                     webrequest.ContentType = request.GetPostBodyContentType();
                     WriteData(webrequest, request.GetPostBody());
                     return webrequest;
                 }
                 else
                 {
                     return webrequest;
                 }
             }
         case Request.Method.GET:
             {
                 return webrequest;
             }
         case Request.Method.DELETE:
             {
                 webrequest.Method = HttpMethod.DELETE;
                 return webrequest;
             }
         case Request.Method.POST:
             {
                 webrequest.ContentType = request.GetBodyContentType();
                 webrequest.Method = HttpMethod.POST;
                 WriteData(webrequest, request.GetPostBody());
                 return webrequest;
             }
         case Request.Method.PUT:
             {
                 webrequest.ContentType = request.GetBodyContentType();
                 webrequest.Method = HttpMethod.PUT;
                 WriteData(webrequest, request.GetPostBody());
                 return webrequest;
             }
         case Request.Method.HEAD:
             {
                 webrequest.Method = HttpMethod.HEAD;
                 return webrequest;
             }
         case Request.Method.OPTIONS:
             {
                 webrequest.Method = HttpMethod.OPTIONS;
                 return webrequest;
             }
         case Request.Method.TRACE:
             {
                 webrequest.Method = HttpMethod.TRACE;
                 return webrequest;
             }
         case Request.Method.PATCH:
             {
                 webrequest.Method = HttpMethod.PATCH;
                 webrequest.ContentType = request.GetPostBodyContentType();
                 WriteData(webrequest, request.GetPostBody());
                 return webrequest;
             }
         default:
             {
                 throw new InvalidOperationException("δ֪����ʽ");
             }
     }
 }