110,536
社区成员
发帖
与我相关
我的任务
分享
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.0.232:8360/rule_conf/index_core.htm?product=url&business_type=1");
request.CookieContainer = cookieContainer;
request.Accept = "text/html, application/xhtml+xml, */*";
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
request.Method = "Get";
request.Headers.Add("Accept-Encoding: gzip, deflate");
request.Headers.Add("Accept-Language: zh-CN");
request.KeepAlive = true;
request.GetResponse();
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create("http://192.168.0.232:8360/rule_conf/index_core.htm?product=url&business_type=1");
request1.CookieContainer = cookieContainer;
request1.Accept = "text/html, application/xhtml+xml, */*";
request1.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
request1.Method = "Post";
request1.Headers.Add("Accept-Encoding: gzip, deflate");
request1.Headers.Add("Accept-Language: zh-CN");
request1.KeepAlive = true;
string data = "op=add&rule_num=&apply=N&rule_id=wdid%3A150&business_type=1&rules=%28return_levelsublevel%3A70.0%29%26%26%28file_path%3Alike%2Clinetest4%29&type=in®ionlist=100000&hit_limit=&rule_desc=test&del_reasion=";
request1.ContentLength = data.Length;
StreamWriter sw = new StreamWriter(request1.GetRequestStream(), Encoding.ASCII);
sw.Write(data);
sw.Flush();
request1.GetResponse();
}
#coding: gbk
import urllib
import urllib2
import cookielib
import httplib2
Entryurl = 'http://192.168.0.232:8360/rule_conf/index_core.htm?product=url&business_type=1'
http = httplib2.Http()
headers = {'User-agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1)',
'Accept':'text/html, application/xhtml+xml, */*',
'Referer':'http://192.168.0.232:8360/rule_conf/',
'Accept-Encoding':'gzip, deflate',
'Host':'192.168.0.232:8360',
'Connection':'Keep-Alive',
'Accept-Language':'zh-CN'}
response, content = http.request(Entryurl, 'GET', headers=headers)
cookie = re.split(';',response['set-cookie'])[0]
url = 'http://192.168.0.232:8360/rule_conf/index_core.htm?product=url&business_type=1'
data = {'op':'add',
'rule_num':'',
'apply':'N',
'rule_id':'wdid:2',
'business_type':'1',
'rules':'(return_levelsublevel:40.0)&&(file_path:like,自动化测试)',
'type':'in',
'regionlist':'100000',
'hit_limit':'',
'rule_desc':'test',
'del_reasion':'',
}
postData = urllib.urlencode(data)
headers ={'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1)',
'Content-Type':'application/x-www-form-urlencoded',
'Cache-Control':'no-cache',
'Accept': 'text/html, application/xhtml+xml, */*',
'Connection': 'Keep-Alive',
'Referer':'http://192.168.0.232:8360/rule_conf/index_core.htm?product=url&business_type=1',
'Accept-Language': 'zh-CN',
'Cookie': cookie,
#User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
'Accept-Encoding: gzip': 'deflate',
'Host': '192.168.0.232:8360',
'Connection': 'Keep-Alive',
'Cache-Control':'no-cache'}
response, content = http.request(Entryurl, 'POST', headers=headers,body = postData)
print response
print content