title: Why is this HTTP post not working on the website?
body: <p>I am trying to make a POST on a website, which adds something to a log. When I do it through a browser, everything works, and when I do it through my program, nothing is added.</p>
  
  <p>I get a "200" response in both browser and program.</p>
  
  <p>Textview in Fiddler (on browser):</p>
  
  <pre><code>utf8=%E2%9C%93&amp;authenticity_token=K32ch7TAQI9PIMInQAVeGFS2lEn5APs5WkKCb3Ep%2Bj8%3D&amp;message%5Btext%5D=Hej&amp;commit=Send
  </code></pre>
  
  <p>Textview in Fiddler (my program):</p>
  
  <pre><code>utf8=%e2%9c%93&amp;authenticity_token=K32ch7TAQI9PIMInQAVeGFS2lEn5APs5WkKCb3Ep%2bj8%3d&amp;message%5btext%5d=Hej&amp;commit=Send
  </code></pre>
  
  <p>RAW (my browser):</p>
  
  <pre><code>POST url HTTP/1.1
  Host: www.website.com
  Connection: keep-alive
  Content-Length: 121
  Accept: */*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript
  Origin: http://www.website.com
  X-CSRF-Token: K32ch7TAQI9PIMInQAVeGFS2lEn5APs5WkKCb3Ep+j8=
  User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36
  X-Requested-With: XMLHttpRequest
  Content-Type: application/x-www-form-urlencoded
  Referer: http://www.website.com
  Accept-Encoding: gzip,deflate,sdch
  Accept-Language: en-US,en;q=0.8,da;q=0.6
  Cookie: fbm_238256999842=base_domain=.domain.com; __lc.visitor_id.2885992=S1376210797.6c94fdbc2a; user_age=23; _single_session=BAh7CkkiD3Nlc3Npb25faWQGOgZFRkkiJWQ4YWFlOTg0MDNkZGYyYWQ1MTA1NzljZjEyZGRlY2UxBjsAVEkiFmluZGV4X3NwbGFzaF8yMDEzBjsARmkGSSIZd2FyZGVuLnVzZXIudXNlci5rZXkGOwBUWwhJIglVc2VyBjsARlsGaQPKwAxJIgxuZXRkYXRlBjsARkkiGm9ubGluZV9zdGF0dXNfdG91Y2hlZAY7AEZJdToJVGltZQ0QYxyAgaLOrQo6C0Bfem9uZUkiCUNFU1QGOwBUOg1uYW5vX251bWkC4AM6DW5hbm9fZGVuaQY6DXN1Ym1pY3JvIgeZIDoLb2Zmc2V0aQIgHEkiEF9jc3JmX3Rva2VuBjsARkkiMUszMmNoN1RBUUk5UElNSW5RQVZlR0ZTMmxFbjVBUHM1V2tLQ2IzRXArajg9BjsARg%3D%3D--676129dd5e8610525c75600989f7c563517938f2; __utma=165150141.1159381462.1376210785.1379964911.1380038586.30; __utmb=165150141.44.10.1380038586; __utmc=165150141; __utmz=165150141.1378658500.16.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); _ga=GA1.2.1159381462.1376210785; __ar_v4=CJLW5TTORNEXTFNCM45SA7%3A20130911%3A117%7CO7VFZLVH2JECBJGXBDZU4E%3A20130911%3A117%7CY2N2UAMJNBCF7NZLP3EBM6%3A20130911%3A89%7CXMTUNIBTWVDONDLY4CFR77%3A20130911%3A27%7CXXYWGZWUVFE5LE42VCBQMT%3A20130924%3A1; fbsr_238256999842=dsfZCzzwfV5u33j_Fy7Gko7iSKPf3gNOozmQS07K3xE.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiJBUUNHVmMxTnhYV0F0R05PSExxQlJtTjVVTXkyQ09DcmdpT0VJbXBzcTJ4aE1UeVk0Vnh1RlZZTXYwcUxPVVYwOG9nMzNZdVRuVGhNaElHMkRCTVltVnhidFFZc21hV3JpZGo1Rk45cmxROXRFWFdLZ0dHdFdvUmJyN19SMmVNd2l2Z29mT1o5YmlxVTVJVUctZVhiS1duTXlIaVNIa0hEaG5ib0dfMExNZjRhcWgzMHliV3pxeEw0Z1kyMUxsX2g2elZqT2xOdEdScTR3SUFEbWVBWW9LWWUwN0RWNUlhXzNOSlRKdW1fUGJmTnVQMzJWd2M0TV9sZ1U3bXk0ejl3aXhJZGthaDlNbjlkbE5iNW5zQ0NXbVFFb1I2c21QWG1FekZLdDlQQ1RNSGZVVFRGVVJ5RVpNd3piT0FZV0dIaEtCSSIsImlzc3VlZF9hdCI6MTM4MDA0MTA2NywidXNlcl9pZCI6IjU1NzQzMTg4NSJ9
  
  utf8=%E2%9C%93&amp;authenticity_token=K32ch7TAQI9PIMInQAVeGFS2lEn5APs5WkKCb3Ep%2Bj8%3D&amp;message%5Btext%5D=Hej&amp;commit=Send
  </code></pre>
  
  <p>RAW (my program):</p>
  
  <pre><code>POST url HTTP/1.1
  Content-Type: application/x-www-form-urlencoded
  User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36
  Accept: */*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript
  Accept-Encoding: gzip,deflate,sdch
  Accept-Language: en-US,en;q=0.8,da;q=0.6
  Origin: http://www.website.com
  Referer: http://www.website.com
  X-CSRF-Token: w2cOY0v1YW5/aB9Po/A8N8LD50p8J/Rxkx9NzMkEWBY=
  X-Requested-With: XMLHttpRequest
  Cache-Control: max-age=0
  Host: www.website.com
  Cookie: __lc.visitor_id.2885992=S1376210797.6c94fdbc2a; __ar_v4=CJLW5TTORNEXTFNCM45SA7%3A20130911%3A91%7CO7VFZLVH2JECBJGXBDZU4E%3A20130911%3A91%7CY2N2UAMJNBCF7NZLP3EBM6%3A20130911%3A72%7CXMTUNIBTWVDONDLY4CFR77%3A20130911%3A18%7CXXYWGZWUVFE5LE42VCBQMT%3A20130924%3A1; user_age=23; _ga==GA1.2.1159381462.1376210785; fbsr_238256999842=xA1ic3Y9Hr--2X7kOrvK_4PjFzSsDSSIGPsZMBBIY6Q.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiJBUUJIQllHd0J3YWRBa0pzX0Vtd3d1LXc3LWM0MmxxM0RGbVRtOUg3cTZSdWNIcG1penc3dU0yVUZGWDR3UlpfTkdZX3BVXzRSN2lsUU5lVTRxNlltRUNISVdieFRxSmVOZUZkUFktSmIyZmR6ZVd1&amp;; __utma=165150141.1159381462.1376210785.1379964911.1380038586.30&amp;; __utmb=165150141.44.10.1380038586&amp;; __utmc=165150141&amp;; __utmz=165150141.1378658500.16.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)&amp;; _single_session=BAh7CkkiD3Nlc3Npb25faWQGOgZFRkkiJWQ4YWFlOTg0MDNkZGYyYWQ1MTA1NzljZjEyZGRlY2UxBjsAVEkiFmluZGV4X3NwbGFzaF8yMDEzBjsARmkGSSIZd2FyZGVuLnVzZXIudXNlci5rZXkGOwBUWwhJIglVc2VyBjsARlsGaQPKwAxJIgxuZXRkYXRlBjsARkkiGm9ubGluZV9zdGF0dXNfdG91Y2hlZAY7AEZJdToJVG&amp;
  Content-Length: 126
  </code></pre>
  
  <p>I guess my question is:</p>
  
  <p>When I post the same data, to the same URL, what could stop it from working? I guess it is some of my headers, but I thought as long as the contenttype and some other important headers match, everything is good.</p>
  
  <p>I am pretty sure the authenticity_token is the same always (it is when I use the website), so I don't think that's the problem.</p>
  
  <p>What could be the problem here? What headers should I worry a lot about? How about cookies?</p>
  
  <p>Right now I hardcore all the data and tokens, until I've got it to work. However, my C# web request is here:</p>
  
  <pre><code> private static HttpWebRequest GetHttpRequest(string url, CookieContainer container, bool post)
          {
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
              request.Method = post ? "POST" : "GET";
              request.ContentType = "application/x-www-form-urlencoded";
              request.UserAgent =
                  "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36";
              request.Accept = "*/*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript";
              request.Headers.Add("Accept-Encoding","gzip,deflate,sdch");
              request.Headers.Add("Accept-Language", "en-US,en;q=0.8,da;q=0.6");
  
              //request.Headers.Add("Cache-Control", "max-age=0");
              request.CookieContainer = container;
              request.KeepAlive = true;
              request.Expect = "";
  
              request.Headers.Add("Origin", "http://www.domain.com");
              request.Referer = "http://www.domain.com";
              request.Headers.Add("X-CSRF-Token", "w2cOY0v1YW5/aB9Po/A8N8LD50p8J/Rxkx9NzMkEWBY=");
              request.Headers.Add("X-Requested-With", "XMLHttpRequest");
              return request;
          }
  </code></pre>
  
  <p>In C#, my cookies and data:</p>
  
  <pre><code>  NameValueCollection col = new NameValueCollection();
          col.Add("utf8", "✓");
          col.Add("authenticity_token", "K32ch7TAQI9PIMInQAVeGFS2lEn5APs5WkKCb3Ep+j8=");
          col.Add("message[text]", messages.TextBody);
          col.Add("commit", "Send");
  
  
          container = new CookieContainer();
          container.Add(new Cookie("__lc.visitor_id.2885992", "S1376210797.6c94fdbc2a") { Domain = "domain.com", Expires = DateTime.Now.AddDays(1) });
          container.Add(new Cookie("__ar_v4", "CJLW5TTORNEXTFNCM45SA7%3A20130911%3A91%7CO7VFZLVH2JECBJGXBDZU4E%3A20130911%3A91%7CY2N2UAMJNBCF7NZLP3EBM6%3A20130911%3A72%7CXMTUNIBTWVDONDLY4CFR77%3A20130911%3A18%7CXXYWGZWUVFE5LE42VCBQMT%3A20130924%3A1") { Domain = "domain.com", Expires = DateTime.Now.AddDays(1) });
          container.Add(new Cookie("user_age", "23") { Domain = "domain.com", Expires = DateTime.Now.AddDays(1) });
          container.Add(new Cookie("_ga", "=GA1.2.1159381462.1376210785") { Domain = "domain.com", Expires = DateTime.Now.AddDays(1) });
          container.Add(new Cookie("fbsr_238256999842", "xA1ic3Y9Hr--2X7kOrvK_4PjFzSsDSSIGPsZMBBIY6Q.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiJBUUJIQllHd0J3YWRBa0pzX0Vtd3d1LXc3LWM0MmxxM0RGbVRtOUg3cTZSdWNIcG1penc3dU0yVUZGWDR3UlpfTkdZX3BVXzRSN2lsUU5lVTRxNlltRUNISVdieFRxSmVOZUZkUFktSmIyZmR6ZVd1…") { Domain = "domain.com", Expires = DateTime.Now.AddDays(1) });
          container.Add(new Cookie("__utma", "165150141.1159381462.1376210785.1379964911.1380038586.30…") { Domain = "domain.com", Expires = DateTime.Now.AddDays(1) });
          container.Add(new Cookie("__utmb", "165150141.44.10.1380038586…") { Domain = "domain.com", Expires = DateTime.Now.AddDays(1) });
          container.Add(new Cookie("__utmc", "165150141…") { Domain = "domain.com", Expires = DateTime.Now.AddDays(1) });
          container.Add(new Cookie("__utmz", "165150141.1378658500.16.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)…") { Domain = "domain.com", Expires = DateTime.Now.AddDays(1) });
          container.Add(new Cookie("_single_session", "BAh7CkkiD3Nlc3Npb25faWQGOgZFRkkiJWQ4YWFlOTg0MDNkZGYyYWQ1MTA1NzljZjEyZGRlY2UxBjsAVEkiFmluZGV4X3NwbGFzaF8yMDEzBjsARmkGSSIZd2FyZGVuLnVzZXIudXNlci5rZXkGOwBUWwhJIglVc2VyBjsARlsGaQPKwAxJIgxuZXRkYXRlBjsARkkiGm9ubGluZV9zdGF0dXNfdG91Y2hlZAY7AEZJdToJVG…") { Domain = "domain.com", Expires = DateTime.Now.AddDays(1) });
  </code></pre>