Closed SwpuEsine closed 2 years ago
The first issue is that bash cannot parse this as pasted here because of the !
inside the double quotes in the cookie argument.
But even after fixing that, the node querystring library barfs on the given data
argument.
Not sure how to address that yet, but here's a more readable version of the command to use in a test later on.
curl -k -i --raw -o 0.dat -X POST \
-d "crmActiveCustId=undefined&crmActiveIdNo=undefined&crmActiveOpCode=null&crmActiveSessionId=undefined&DemixRandomNumParam=48016117888710&phone_no=15882033223&fullThemePath=%%2Fnresources%%2FUI" "http://10.112.9.70:11001/npage/public/ajax_getCustSellMsgAdd.jsp" \
-H "x-requested-with: XMLHttpRequest" \
-H "Accept-Language: zh-CN" \
-H "Referer: http://10.112.9.70:11001/npage/portal/cust/fCustMarketingInfo.jsp?phone_no=15882033223&op_track_time=20171113134243540" \
-H "Accept: text/html, /" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept-Encoding: gzip, deflate" \
-H "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Shuame; .NET4.0C; .NET4.0E)" \
-H "Host: 10.112.9.70:11001" -H "Connection: Keep-Alive" -H "Pragma: no-cache" \
-H 'Cookie: CrmSessionID=o4Cz5Jc6FBKgvDGsP6Gkv4IA6uGRBBaMsxivI-pq9tGBDsBzTJQO!1742106468; CSRF_TOKEN=48016117888710; LOGIN_INFO=ave120015|11|1435408'
You can get it to cleanly parse by removing the extra percent signs. That yields this output:
import requests
cookies = {
'CrmSessionID': 'o4Cz5Jc6FBKgvDGsP6Gkv4IA6uGRBBaMsxivI-pq9tGBDsBzTJQO!1742106468',
'CSRF_TOKEN': '48016117888710',
'LOGIN_INFO': 'ave120015|11|1435408',
}
headers = {
'x-requested-with': 'XMLHttpRequest',
'Accept-Language': 'zh-CN',
'Referer': 'http://10.112.9.70:11001/npage/portal/cust/fCustMarketingInfo.jsp?phone_no=15882033223&op_track_time=20171113134243540',
'Accept': 'text/html, /',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Shuame; .NET4.0C; .NET4.0E)',
'Host': '10.112.9.70:11001',
'Connection': 'Keep-Alive',
'Pragma': 'no-cache',
}
data = [
('crmActiveCustId', 'undefined'),
('crmActiveIdNo', 'undefined'),
('crmActiveOpCode', 'null'),
('crmActiveSessionId', 'undefined'),
('DemixRandomNumParam', '48016117888710'),
('phone_no', '15882033223'),
('fullThemePath', '/nresources/UI'),
]
response = requests.post('http://10.112.9.70:11001/npage/public/ajax_getCustSellMsgAdd.jsp', headers=headers, cookies=cookies, data=data, verify=False)
The way forward here is probably to attempt a parse so we can build a nice dict in the python output, but if it fails, just use the raw string.
it may be because %% use % replace %% then decode it can fix
Those %%
are the issue and it's the same issue as https://github.com/curlconverter/curlconverter/issues/334#issuecomment-1067337819
When we convert -d
to a dict, requests will url-encode both sides, whereas if we leave it as a string it will just pass it straight through, like curl.
If you try both of these requests with nc -kl 8888
, they'll send the exact same data (only the values in the cookie and some headers are in a different order)
curl -k -i --raw -o 0.dat -X POST \
-d "crmActiveCustId=undefined&crmActiveIdNo=undefined&crmActiveOpCode=null&crmActiveSessionId=undefined&DemixRandomNumParam=48016117888710&phone_no=15882033223&fullThemePath=%%2Fnresources%%2FUI" "http://localhost:8888/npage/public/ajax_getCustSellMsgAdd.jsp" \
-H "x-requested-with: XMLHttpRequest" \
-H "Accept-Language: zh-CN" \
-H "Referer: http://10.112.9.70:11001/npage/portal/cust/fCustMarketingInfo.jsp?phone_no=15882033223&op_track_time=20171113134243540" \
-H "Accept: text/html, /" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept-Encoding: gzip, deflate" \
-H "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Shuame; .NET4.0C; .NET4.0E)" \
-H "Host: 10.112.9.70:11001" -H "Connection: Keep-Alive" -H "Pragma: no-cache" \
-H 'Cookie: CrmSessionID=o4Cz5Jc6FBKgvDGsP6Gkv4IA6uGRBBaMsxivI-pq9tGBDsBzTJQO!1742106468; CSRF_TOKEN=48016117888710; LOGIN_INFO=ave120015|11|1435408'
import requests
cookies = {
'CrmSessionID': 'o4Cz5Jc6FBKgvDGsP6Gkv4IA6uGRBBaMsxivI-pq9tGBDsBzTJQO!1742106468',
'CSRF_TOKEN': '48016117888710',
'LOGIN_INFO': 'ave120015|11|1435408',
}
headers = {
'x-requested-with': 'XMLHttpRequest',
'Accept-Language': 'zh-CN',
'Referer': 'http://10.112.9.70:11001/npage/portal/cust/fCustMarketingInfo.jsp?phone_no=15882033223&op_track_time=20171113134243540',
'Accept': 'text/html, /',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Shuame; .NET4.0C; .NET4.0E)',
'Host': '10.112.9.70:11001',
'Connection': 'Keep-Alive',
'Pragma': 'no-cache',
}
data = 'crmActiveCustId=undefined&crmActiveIdNo=undefined&crmActiveOpCode=null&crmActiveSessionId=undefined&DemixRandomNumParam=48016117888710&phone_no=15882033223&fullThemePath=%%2Fnresources%%2FUI'
response = requests.post('http://localhost:8888/npage/public/ajax_getCustSellMsgAdd.jsp', headers=headers, cookies=cookies, data=data, verify=False)
When I convert the curl in fiddler,it occus wrong, Below is the curl
curl -k -i --raw -o 0.dat -X POST -d "crmActiveCustId=undefined&crmActiveIdNo=undefined&crmActiveOpCode=null&crmActiveSessionId=undefined&DemixRandomNumParam=48016117888710&phone_no=15882033223&fullThemePath=%%2Fnresources%%2FUI" "http://10.112.9.70:11001/npage/public/ajax_getCustSellMsgAdd.jsp" -H "x-requested-with: XMLHttpRequest" -H "Accept-Language: zh-CN" -H "Referer: http://10.112.9.70:11001/npage/portal/cust/fCustMarketingInfo.jsp?phone_no=15882033223&op_track_time=20171113134243540" -H "Accept: text/html, /" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept-Encoding: gzip, deflate" -H "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Shuame; .NET4.0C; .NET4.0E)" -H "Host: 10.112.9.70:11001" -H "Connection: Keep-Alive" -H "Pragma: no-cache" -H "Cookie: CrmSessionID=o4Cz5Jc6FBKgvDGsP6Gkv4IA6uGRBBaMsxivI-pq9tGBDsBzTJQO!1742106468; CSRF_TOKEN=48016117888710; LOGIN_INFO=ave120015|11|1435408"