0

I`m try to post a data to specific url and get response and save it in the file with curl and no problem with it. This webpage post a data and if data is correct show response webpage, and if not redirect to url like that:

http://example.com/url/foo/bar/error

My code is:

curl --fail --user-agent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36"  --data "mydataexample" --referer "http://example.com/url/foo/bar" http://example.com/url/foo/bar --output test.html

But when code in python with requests always status_code is OK [200] even with wrong data! and no exist correct response to save! Here is my python code:

import requests
data = 'myexampledata'
headers = { 'referer':'http://example.com/url/foo/bar' ,'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36' }
url = 'http://example.com/url/foo/bar'
r = requests.post(url,params=data,headers=headers)
# check headers and status_code for test if data is wrong...
print r.headers
print r.status_code

And now, How write a python code to solve this problem and exactly work same as curl command? Any advise with requests or pycurl to fix it?

The Alien
  • 45
  • 6
  • I advise You that use Postmmam, this allow You see los request and response, can be that the format of request not is recognizable by Server. – julian salas Aug 02 '16 at 12:05
  • Are you sure that `data` (`params`) is just a string? Maybe it should be something like `data = {'required_data': 'myexampledata'}`? Also try to send `r = requests.post(url,data=data)` without specifying headers (let `requests` do this instead) – Andersson Aug 02 '16 at 14:02
  • @Andersson, yea, I'm sure and test with requests.post(url,data=data) , even with requests.request('POST', url, data=data) but same wrong result... – The Alien Aug 02 '16 at 18:49

0 Answers0