0

ログに何かを追加する Web サイトで POST を作成しようとしています。ブラウザで実行するとすべてが機能し、プログラムで実行すると何も追加されません。

ブラウザとプログラムの両方で「200」応答が返されます。

Fiddler の Textview (ブラウザ上):

utf8=%E2%9C%93&authenticity_token=K32ch7TAQI9PIMInQAVeGFS2lEn5APs5WkKCb3Ep%2Bj8%3D&message%5Btext%5D=Hej&commit=Send

Fiddler の Textview (私のプログラム):

utf8=%e2%9c%93&authenticity_token=K32ch7TAQI9PIMInQAVeGFS2lEn5APs5WkKCb3Ep%2bj8%3d&message%5btext%5d=Hej&commit=Send

RAW (私のブラウザ):

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&authenticity_token=K32ch7TAQI9PIMInQAVeGFS2lEn5APs5WkKCb3Ep%2Bj8%3D&message%5Btext%5D=Hej&commit=Send

RAW (私のプログラム):

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&; __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)&; _single_session=BAh7CkkiD3Nlc3Npb25faWQGOgZFRkkiJWQ4YWFlOTg0MDNkZGYyYWQ1MTA1NzljZjEyZGRlY2UxBjsAVEkiFmluZGV4X3NwbGFzaF8yMDEzBjsARmkGSSIZd2FyZGVuLnVzZXIudXNlci5rZXkGOwBUWwhJIglVc2VyBjsARlsGaQPKwAxJIgxuZXRkYXRlBjsARkkiGm9ubGluZV9zdGF0dXNfdG91Y2hlZAY7AEZJdToJVG&
Content-Length: 126

私の質問は次のとおりです。

同じデータを同じ URL に投稿すると、何が機能しなくなる可能性がありますか? 私のヘッダーの一部だと思いますが、contenttype とその他の重要なヘッダーが一致していれば、すべて問題ないと思いました。

私は、authenticity_token が常に同じであると確信しているので (Web サイトを使用する場合)、それは問題ではないと思います。

ここで何が問題になる可能性がありますか?どのヘッダーを気にする必要がありますか? クッキーはどうですか?

現在、すべてのデータとトークンをハードコア化して、機能するようにしています。ただし、私の C# Web リクエストは次のとおりです。

 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;
        }

C# では、私の Cookie とデータ:

  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) });
4

1 に答える 1