Пример #1
0
        public HttpResponseMessage Put()
        {
            var existingFormValues = GetSampleData().form;
            var newFormValues = Request.Content.ReadAsFormDataAsync().Result;
            bool foundKey = false;
            foreach (var key in newFormValues.AllKeys)
            {
                 if(existingFormValues.ContainsKey(key))
                 {
                     foundKey = true;
                     if (existingFormValues[key].ToString() != newFormValues[key])
                     {
                         existingFormValues[key] = newFormValues[key];
                     }
                     else
                     {
                         var response = Request.CreateResponse(HttpStatusCode.NotModified);
                         response.ReasonPhrase = "Resource not modified";
                         return response;
                     }
                 }
            }
               if(!foundKey)
               {
               return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Key not found");
               }

            var sampleData = new SampleData
                                 {
                                     url = Request.RequestUri.ToString(),
                                     headers = GetRequestHeaders(),
                                     origin = UserIpAddress,
                                     form = existingFormValues,
                                 };
            return Request.CreateResponse(HttpStatusCode.OK,
                                   sampleData);
        }
Пример #2
0
 public HttpResponseMessage Delete(string key)
 {
     var existingFormValues = GetSampleData().form;
     existingFormValues.Remove(key);
     var sampleData = new SampleData()
                         {
                             url = Request.RequestUri.ToString(),
                             headers = GetRequestHeaders(),
                             origin = UserIpAddress,
                             form = existingFormValues
                         };
     return Request.CreateResponse(HttpStatusCode.OK,
                            sampleData);
 }
Пример #3
0
 public HttpResponseMessage Post()
 {
     var existingFormValues = GetSampleData().form;
     var newFormValues = Request.Content.ReadAsFormDataAsync().Result;
     foreach (var key in newFormValues.AllKeys)
     {
        existingFormValues.Add(key, newFormValues[key]);
     }
     var sampleData = new SampleData
                          {
                              url = Request.RequestUri.ToString(),
                              headers = GetRequestHeaders(),
                              origin = UserIpAddress,
                              form = existingFormValues
                          };
     return Request.CreateResponse(HttpStatusCode.OK,
                            sampleData);
 }
Пример #4
0
 public static SampleData WithDefaults()
 {
     var d = new SampleData { form = new Dictionary<string, object>() { { "k0", "v0" } } };
     return d;
 }