fiddler與python post請求筆記

python3

1.fiddler抓包,若textview中爲一串字符串,如下圖所示:

則我們構造的data,應爲如下格式:

    from urllib import parse
    import urllib.request
    post_data =     {'flag':1,'BLC':0,'BLC_level':8,'light_restrain':1,'light_restrain_mode':0,'light_restrain_level0':8,
'light_restrain_level1':8,'PFR':50,'formatType':'P','MVR':0,'MHR':0,
'WDR':0,'WDR_level':8,'DDS':0,'DS':0,'defog_state':0,'defog_level':8,'Distortion_correction_mode':0,
'Distortion_correction_value':1}


    post_data = parse.urlencode(post_data).encode('utf-8')

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36'
    }
    
    url = "http://*****"
    resp = urllib.request.Request(url= url,data = post_data , headers=headers)#post_data位json編碼
    response = urllib2.urlopen(resp)

 2.若post數據爲json格式,如下圖所示 :

 

 由於POST的數據是json格式的,需要使用json.dumps(post_data)將post_data轉換爲字符串,再進行編碼

     from urllib import parse
     import urllib.request
     post_data = {"SceneMode":scene_str,
    "BasicCMDConf":
    {"MVR_":0,"MHR_":0,"BLC_":0,"BLC_level_":8,"WDR_":0,
    "WDR_mode_":0,"WDR_level_":8,"light_restrain_":mode,
    "light_restrain_mode_":mode12,"light_restrain_level0_":level,
    "light_restrain_level1_":8,"DDS_":0,"DS_":0,
    "contrast_strength_":1,"defog_state_":0,"defog_level_":8,
    "Distortion_correction_mode":"0","Distortion_correction_value":"1"},
    "AEConf":{"AEMode_Select_":0,"Iris_select_":0,
    "IrisMode_ws":2,"Irislevel_ws":9,"Irisdeflevel_ws":99,
    "C2B_Switch_Select_":2,"IRC_Time_":20,"ICR_Sens_":0,"IR_light_":"null",
    "Fill_light_":0,"maxAE_Select_":48,"ShutterSpeed_":10,
    "startShutterSpeed_":15,"endShutterSpeed_":8,"AEGain_":1,
    "PowerMode_":0,"PowerValue_":99},
    "General":{"ImgBrightness_G_":78,"EdgeStrength_G_":128,
    "ImgHue_G_":128,"ImgContrast_G_":128,"ImgSaturation_G_":128,
    "ImgDenoise_G_":128},"WBConf":{"WBM_":0,"WBRG_":0,"WBBG_":0}}

    headers = {
     'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36'
    }
    
    url = "http://*****"

    resp = urllib.request.Request(url= url,data = json.dumps(post_data).encode('utf-8') , headers=headers)#post_data位json編碼
    response = urllib.request.urlopen(resp)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章