请求有效载荷编码

时间:2018-09-19 09:30:54

标签: python python-requests

我使用请求来假装firefox,并且从提琴手那里,我看到标题相同,但是SystaxView不相同

payload = {'searchType':'U'}
s.post(url,data=payload)

但出现错误500,从语法视图中,我在请求中看到它将更改为searchType=U 但是Real浏览器将输出searchType='U'

我尝试过payload = {'searchType':'\'U\''}在语法视图中会变成searchType=%27U%27

有什么主意吗?我只发现1个差异,因此我怀疑它将触发500个错误。

import requests

s=requests.Session()
s.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0'})
s.get('http://gls.fehd.gov.hk/fehd_lgs/jsp/search/searchMainPage.jsp?lang=zh_TW')
s.headers.update({'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'X-Requested-With': 'XMLHttpRequest'})
s.headers.update({'Referer': 'http://gls.fehd.gov.hk/fehd_lgs/jsp/search/searchMainPage.jsp?lang=zh_TW', 'HOST':'gls.fehd.gov.hk'})
s.headers.update({'Accept': 'application/xml, text/xml, */*; q=0.01'})
payload={'searchType':'U','deceased_surName':'','deceased_firstName':'','deceased_age':'','deceased_gender':'M','deceased_nationality':'','deathYear':'','deathMonth':'default','deathDay':'default','burialYear':'','burialMonth':'default','burialDay':'default','sectionNo':'','graveNo':''}

url='http://gls.fehd.gov.hk/FEHD_LGS/util/getSearchResult.jsp'

s.post(url,data=payload)

3 个答案:

答案 0 :(得分:0)

如果您的服务器处理json格式的发布有效负载,请先将您的有效负载格式化为json。

import requests
import json

url = "http://someurl.com/"

# format for json payload
def post(url, param):
       payload = json.dumps(param)
       payload = payload.replace(", ", ",")
       payload = payload.replace("{", "{\n\t")
       payload = payload.replace("\",", "\",\n\t")
       payload = payload.replace("}", "\n}")
       return response = requests.request("POST", url, data=payload)

payloads = dict(searchType ='U')
response = post(url, payloads)
print(response.response.text)

答案 1 :(得分:0)

如果您要发送的值为'U',则可以帮助您正确发送。

payload = {'searchType': "'U'"}
s.post(url,data=payload)

编辑:

我认为您不需要发出帖子请求。尝试发出获取请求:

url='http://gls.fehd.gov.hk/FEHD_LGS/util/getSearchResult.jsp' 

response = requests.get("%s?%s" % (url, "searchType='U'&deceased_surname=%E6%A5%8A&deceased_firstname=&deceased_age=&deceased_gender='M'&deceased_nationality=&deathYear=&deathMonth=default&deathDay=default&burialYear=&burialMonth=default&burialDay=default&sectionNo=&graveNo=–"))

print(response.content.decode())

select * from cccs_dece_info where SITE_ID in (12,13) and GRAVE_TYPE in ('U') and ( DECEASED_CNAME like '楊%' or upper(DECEASED_ENAME) like '楊 %' or DECEASED_ALIAS = '楊' or DECEASED_ALIAS = '楊')  and ( DECEASED_SEX_CODE in ('M', 'U'))  and ( GRAVE_NO='–' )
java.sql.SQLSyntaxErrorException: ORA-01722: invalid number

答案 2 :(得分:0)

代码没有任何问题,您的url /服务器似乎有问题,..我检查了Postman的情况是this picture

您是否尝试过另一种方法来执行POST负载? (例如:邮递员或PHP POST方法)