F
F
Fridary2016-07-22 22:37:48
Python
Fridary, 2016-07-22 22:37:48

Is it possible to block POST requests from localhost to a site?

I need to parse articles from the portal ras.arbitr.ru
On this resource, after clicking on the search button, a POST request is sent to ras.arbitr.ru/Ras/Search with parameters

{"GroupByCase":false,"Count":25,"Page":1,"DateFrom":"2000-01-01T00:00:00","DateTo":"2030-01-01T23:59:59",
"Sides":[],"Judges":[],"Cases":[],"Text":""}

We get the answer in json format with all articles (25 pieces per page):
{"Result":{"PagesCount":40,"TotalCount":23840237,"NumOnPage":25,"Page":1,"ReturnCount":1000,"Items":[{"Id":"54ec7dd5-10cd-4425-b8c0-46f509eec71f","CaseId":"6ba8cdf0-7df8-4708-8b03-471ce85eb997","RegistrationDate":"18.02.2025","InstanceNumber":"А71-4617/2012"...}

I wrote a simple python script to parse a POST request:
import requests
import json
payload = {"GroupByCase":False,"Count":25,"Page":1,"DateFrom":"2000-01-01T00:00:00","DateTo":"2030-01-01T23:59:59","Sides":[],"Judges":[],"Cases":[],"Text":""}
r = requests.post("http://ras.arbitr.ru/Ras/Search", data=payload)
print(r.status_code, r.reason)

And the response from the server:
(500, 'Internal Server Error')
The same response with a different library and with all the headers:
data = json.dumps({"GroupByCase":False,"Count":25,"Page":1,"DateFrom":"2000-01-01T00:00:00","DateTo":"2030-01-01T23:59:59","Sides":[],"Judges":[],"Cases":[],"Text":""})

c = pycurl.Curl()
c.setopt(pycurl.URL, 'http://ras.arbitr.ru/Ras/Search')
c.setopt(pycurl.HTTPHEADER, [
  "Accept:application/json, text/javascript, */*",
  "Accept-Encoding:gzip, deflate",
  "Accept-Language:en-US,en;q=0.8,ru;q=0.6",
  "Connection:keep-alive",
  "Content-Length:149",
  "Content-Type:application/json",
  "Cookie:ASP.NET_SessionId=eob3w5vypepmykpcsixfpxyv; __utmt=1; CUID=49784dc2-a97e-4249-8c61-415fe5f6f081:QNsAJT4ya5WN7jeL7jCECg==; __utma=160997822.296078651.1469210605.1469210605.1469257019.2; __utmb=160997822.4.10.1469257019; __utmc=160997822; __utmz=160997822.1469210605.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)",
  "Host:ras.arbitr.ru",
  "Origin:http://ras.arbitr.ru",
  "Referer:http://ras.arbitr.ru/",
  "User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
  "X-Requested-With:XMLHttpRequest"
])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, data)
c.perform()

I tried to change the code in different ways, also use httplib instead of the requests library - no result.
Tell me what could be wrong? Can there be a block on ras.arbitr.ru, so that you can send POST requests only from their site? Or maybe I need to send certain headers in the same way?
Thanks

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dimonchik, 2016-07-22
@dimonchik2013

1) pycurl
2) fiddler (well, or there is debugging in Chrome)

V
Vladimir Kuts, 2016-07-23
@fox_12

See what the browser sends in headers. And pass the same.
From user agent, referrer, to cookie transfer

R
Roman Mirilaczvili, 2016-09-16
@2ord

It's probably a cross-origin HTTP request (CORS).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question