欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

fiddler与python post请求笔记

程序员文章站 2022-03-28 11:11:53
...

python3

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

fiddler与python post请求笔记

则我们构造的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格式,如下图所示 :

 fiddler与python post请求笔记

fiddler与python post请求笔记 由于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)

 

相关标签: POST