I have a strange API, it just accept gbk parameters, I capture the data in Windows IE browser, show data with this command:
$ cat 12_Request.txt| iconv -f GBK -t UTF-8
GET http://10.202.15.197:20176/?user_id=1&query_type=GEOSPLIT&address=广东省深圳市宝安&ret_splitinfo=1 HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: zh-CN
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: 10.202.15.197:20176
DNT: 1
Connection: Keep-Alive
As you can see, my data is encode in GBK.
Then I send data with netcat like this:
$ cat 12_Request.txt| nc 10.202.15.197 20176 | iconv -f GBK -t utf-8 # right
HTTP/1.0 200 OK
Content-Type: application/octet-stream
Connection: close
Content-Length: 222
0广东省
深圳市
宝安
but if I send data with UTF-8, I get the wrong response:
$ cat 12_Request.txt | iconv -f GBK -t utf-8 | nc 10.202.15.197 20176 # wrong
HTTP/1.0 200 OK
Content-Type: application/octet-stream
Connection: close
Content-Length: 152
0广东省深圳市宝安
I have tried to send like this in cURL:
curl -v \
--header 'Accept: text/html, application/xhtml+xml, */*' \
--header 'Accept-Language: zh-CN' \
-A 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko' \
--header 'Accept-Encoding: gzip, deflate' \
--header 'Host: 10.202.15.197:20176' \
--header 'DNT: 1' \
--header 'Connection: Keep-Alive' \
http://10.202.15.197:20176?user_id=1&query_type=GEOSPLIT&address=广东省深圳市宝安&ret_splitinfo=1
this doesn't work, it get response as follow:
0广东省深圳市宝安
Then, with data-urlencode:
curl \
--header 'Accept: text/html, application/xhtml+xml, */*' \
--header 'Accept-Language: zh-CN' \
-A 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko' \
--header 'Accept-Encoding: gzip, deflate' \
--header 'Host: 10.202.15.197:20176' \
--header 'DNT: 1' \
--header 'Connection: Keep-Alive' \
http://10.202.15.197:20176 --data-urlencode 'user_id=1&query_type=GEOSPLIT&address=广东省深圳市宝安&ret_splitinfo=1'
this doesn't work, it gets response like this:
10
Also I tried with python,
>>> import requests
>>> url = u"http://10.202.15.197:20176?user_id=1&query_type=GEOSPLIT&address=广东省深圳市宝安&ret_splitinfo=1"
>>> r = requests.get(url.encode('utf-8').decode('gbk'))
>>> print r.text
this doesn't work, the response like this:
u'<?xml version=\'1.0\' encoding=\'GBK\'?>\n\n0\xe9\u015e\x9e\u013a\xb8\xe7\u0179\u02d8\xe9\x90\u015e\xe4\u02dd\u0161\xe7\u0161\x81\xe9\x8d)\x86\u02db\xe7\u0164\u015b\xe7\x80\u0161\u0107\u017c\x86\xe7\x95\xa8\n\n'
解决方案
I think I get the answer
with cURL:
echo "http://10.202.15.197:20176\?user_id\=1\&query_type\=GEOSPLIT\&address\=广东省深圳市宝安\&ret_splitinfo\=1" | iconv -f utf-8 -t gbk | xargs curl
with python
payload = {"user_id": 1, "query_type": "GEOSPLIT", "address": u"广东省深圳市宝安".encode('gbk'), "ret_splitinfo": 1}
r = requests.get("http://10.202.15.197:20176", payload)
print r.text

990

被折叠的 条评论
为什么被折叠?



