c# - Why is this HTTP post not working on the website? -


i trying make post on website, adds log. when through browser, works, , when through program, nothing added.

i "200" response in both browser , program.

textview in fiddler (on browser):

utf8=%e2%9c%93&authenticity_token=k32ch7taqi9piminqavegfs2len5aps5wkkcb3ep%2bj8%3d&message%5btext%5d=hej&commit=send 

textview in fiddler (my program):

utf8=%e2%9c%93&authenticity_token=k32ch7taqi9piminqavegfs2len5aps5wkkcb3ep%2bj8%3d&message%5btext%5d=hej&commit=send 

raw (my browser):

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, 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 (my program):

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, 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 

i guess question is:

when post same data, same url, stop working? guess of headers, thought long contenttype , other important headers match, good.

i pretty sure authenticity_token same (it when use website), don't think that's problem.

what problem here? headers should worry lot about? how cookies?

right hardcore data , tokens, until i've got work. however, c# web request here:

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

in c#, cookies , data:

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

to debug this, capture both working , non-working requests in fiddler.

select both , right-click , choose "compare". determine how 2 requests differ, change code make them match.

the authenticity_token one-time token hidden javascript variable or form field in of prior html document response, , reusing token won't work.

also, did notice authenticity_token url doesn't match app's request's x-csrf-token header match in working request? may problem.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -