码迷,mamicode.com
首页 > Web开发 > 详细

loadrunner上传文件到网盘

时间:2018-07-31 19:15:34      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:turn   pts   webkit   CMF   并且   tag   html   utf-8   type   

有人提问,loadrunner 上传文件搞不好,请求帮忙处理。让提供网址,用fiddler抓包上传部分,主要有3个请求

第一个请求
GET https://yun.xxx.com/api/files/upload/request?groupid=406896460&parentid=0&size=10&name=ae.txt&parent_path=&checkname=true&store=ks3&method=POST HTTP/1.1
Host: yun.xxx.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36
Accept: */*
Referer: https://yun.xxx.com/drive/group/406896460
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22164ede8841f339-032750c7b54867-68151275-1049088-164ede88421341%22%2C%22%24device_id%22%3A%22164ede8841f339-032750c7b54867-68151275-1049088-164ede88421341%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%7D; Hm_lvt_088d7d4ca9fd9c419f6d37e55a2732bb=1532999796; xabqing_autoLoginV1=1; numberOfFailedAttempts=0; xab_sid=V02S4fptWYKB4Yj7C3WnpOkUVibg77Y01475a7a40016f157e9; csrf=weWzjjrbf2AB3cs2wwBBkCCCtA3Dk4BZ; domain=xxx.com

响应:
HTTP/1.1 200 OK
Server: CLOUD ELB 1.0.0
Date: Tue, 31 Jul 2018 08:47:24 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 535
Connection: keep-alive
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Cache-Control: no-cache
Cache-Control: no-store


{"KSSAccessKeyId":"1GL02rRYQxK8s7FQh8dV","Policy":"eyJleHBpcmF0aW9uIjoiMjAxOC0wNy0zMVQwOToxNzoyNC4wMDBaIiwiY29uZGl0aW9ucyI6W3sia2V5IjoidGVtcF8zODQ5MTU0MzNfYjcwMTI2ODRlMTQ4NDMyY2FmN2MwNjk1MTQ0ZDdkNTEifSx7ImJ1Y2tldCI6Indwc2ZpbGUifSx7Ingta3NzLW5ld2ZpbGVuYW1lLWluLWJvZHkiOnRydWV9XX0=","Signature":"/NrpuemYa4Pn0+DXkd81It/bLEo=","exist_fname":false,"fname":"ae.txt","key":"temp_384915433_b7012684e148432caf7c0695144d7d51","result":"ok","stat":"OK","store":"ks3","url":"https://zhstorage.yun.xxx.com/xabfile","x-kss-newfilename-in-body":true}

 第二个请求:

POST https://zhstorage.yun.xxx.com/xabfile HTTP/1.1
Host: zhstorage.yun.xxx.com
Connection: keep-alive
Content-Length: 1009
Origin: https://yun.xxx.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryQKcfp7lhPEaqB3Td
Accept: */*
Referer: https://yun.xxx.com/drive/group/406896460
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9

------WebKitFormBoundaryQKcfp7lhPEaqB3Td
Content-Disposition: form-data; name="key"

temp_384915433_b7012684e148432caf7c0695144d7d51
------WebKitFormBoundaryQKcfp7lhPEaqB3Td
Content-Disposition: form-data; name="Signature"

/NrpuemYa4Pn0+DXkd81It/bLEo=
------WebKitFormBoundaryQKcfp7lhPEaqB3Td
Content-Disposition: form-data; name="KSSAccessKeyId"

1GL02rRYQxK8s7FQh8dV
------WebKitFormBoundaryQKcfp7lhPEaqB3Td
Content-Disposition: form-data; name="Policy"

eyJleHBpcmF0aW9uIjoiMjAxOC0wNy0zMVQwOToxNzoyNC4wMDBaIiwiY29uZGl0aW9ucyI6W3sia2V5IjoidGVtcF8zODQ5MTU0MzNfYjcwMTI2ODRlMTQ4NDMyY2FmN2MwNjk1MTQ0ZDdkNTEifSx7ImJ1Y2tldCI6Indwc2ZpbGUifSx7Ingta3NzLW5ld2ZpbGVuYW1lLWluLWJvZHkiOnRydWV9XX0=
------WebKitFormBoundaryQKcfp7lhPEaqB3Td
Content-Disposition: form-data; name="x-kss-newfilename-in-body"

true
------WebKitFormBoundaryQKcfp7lhPEaqB3Td
Content-Disposition: form-data; name="file"; filename="ae.txt"
Content-Type: text/plain

aaaaaaaaac
------WebKitFormBoundaryQKcfp7lhPEaqB3Td--


响应:
HTTP/1.1 200 OK
Server: nginx/1.13.3
Date: Tue, 31 Jul 2018 08:47:25 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 59
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: newfilename, x-kss-request-id, ETag, Date
Etag: 795d01e0360ef19b3a41ed915443f7c1
Newfilename: ba9da2b1a0584bfc36ef0e5c0007ec3f03913a81
Vary: Origin
X-Kss-Request-Id: 296b72bb-dca6-4c0a-8f1f-b5e921e9051e

{"newfilename":"ba9da2b1a0584bfc36ef0e5c0007ec3f03913a81"}

 

第三个请求:

POST https://yun.xxx.com/api/v3/groups/406896460/files?im_push=1&store=ks3&action= HTTP/1.1
Host: yun.xxx.com
Connection: keep-alive
Content-Length: 203
Origin: https://yun.xxx.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36
Content-Type: application/json
Accept: */*
Referer: https://yun.xxx.com/drive/group/406896460
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22164ede8841f339-032750c7b54867-68151275-1049088-164ede88421341%22%2C%22%24device_id%22%3A%22164ede8841f339-032750c7b54867-68151275-1049088-164ede88421341%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%7D; Hm_lvt_088d7d4ca9fd9c419f6d37e55a2732bb=1532999796; xabqing_autoLoginV1=1; numberOfFailedAttempts=0; xab_sid=V02S4fptWYKB4Yj7C3WnpOkUVibg77Y01475a7a40016f157e9; csrf=weWzjjrbf2AB3cs2wwBBkCCCtA3Dk4BZ; domain=xxx.com

{"groupid":"406896460","parentid":0,"parent_path":[],"name":"ae.txt","secure_guid":"","size":10,"sha1":"ba9da2b1a0584bfc36ef0e5c0007ec3f03913a81","csrfmiddlewaretoken":"weWzjjrbf2AB3cs2wwBBkCCCtA3Dk4BZ"}

响应:
HTTP/1.1 200 OK
Server: CLOUD ELB 1.0.0
Date: Tue, 31 Jul 2018 08:47:26 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 712
Connection: keep-alive
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Accept,Content-Type
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
Access-Control-Allow-Origin: https://yun.xxx.com
Access-Control-Expose-Headers: Accept,Content-Type
X-QReqID: 15330268463565160510584
Cache-Control: no-store

{"id":11329694092,"fileid":11329694092,"groupid":406896460,"parentid":0,"fname":"ae.txt","ftype":"sharefile","fver":1,"fsize":10,"fsha":"ba9da2b1a0584bfc36ef0e5c0007ec3f03913a81","storeid":"","store":9,"secure_guid":"","deleted":false,"ctime":1533026846,"mtime":1533026846,"creator":{"id":384915433,"name":"张三丰","avatar":"https://avatar.qxxx.com/avatar/546L5b636LaF"},"modifier":{"id":384915433,"name":"张三丰","avatar":"https://avatar.qxxx.com/avatar/546L5b636LaF"},"user_acl":{"copy":1,"delete":1,"download":1,"history":1,"move":1,"new_empty":0,"read":1,"rename":1,"secret":1,"share":1,"update":1,"upload":0},"node":0,"storage_host":"zhstorage.yun.xxx.com","preview_host":"zhvdoc.yun.xxx.com","tags":null}

 

分析请求,请求中的cookie,是从登陆中获取到的,由于是帮忙,并且环境无法录制,就直接用web_add_cookie 来让脚本免登陆。第一个请求后会返回一些数据,这些数据要用在第二个请求中,这就需要用关联。同样,第二个请求的响应也返回一些数据,用到第三个请求中。第三个请求发送完毕,上传完成

 

lr脚本如下:

Action()
{
    lr_save_string("ae.txt","filename");
    lr_save_string("weWzjjrbf2AB3cs2wwBBkCCCtA3Dk4BZ","csrf");
    web_add_cookie("sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22164ede8841f339-032750c7b54867-68151275-1049088-164ede88421341%22%2C%22%24device_id%22%3A%22164ede8841f339-032750c7b54867-68151275-1049088-164ede88421341%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%7D; DOMAIN=yun.xxx.com");
    web_add_cookie("sajssdk_2015_cross_new_user=1; DOMAIN=yun.xxx.com");
    web_add_cookie("Hm_lvt_088d7d4ca9fd9c419f6d37e55a2732bb=1532999796; DOMAIN=yun.xxx.com");
    web_add_cookie("xabqing_autoLoginV1=1; DOMAIN=yun.xxx.com");
    web_add_cookie("numberOfFailedAttempts=0; DOMAIN=yun.xxx.com");
    web_add_cookie("xab_sid=V02S4fptWYKB4Yj7C3WnpOkUVibg77Y01475a7a40016f157e9; DOMAIN=yun.xxx.com");




//{"KSSAccessKeyId":"1GL02rRYQxK8s7FQh8dV","Policy":"eyJleHBpcmF0aW9uIjoiMjAxOC0wNy0zMVQwNzoyNzoxMy4wMDBaIiwiY29uZGl0aW9ucyI6W3sia2V5IjoidGVtcF8zODQ5MTU0MzNfNTFiZWJhMTZkZDBkNDVlNGJlODQ4MDI4OTBhZTY0ZGEifSx7ImJ1Y2tldCI6Indwc2ZpbGUifSx7Ingta3NzLW5ld2ZpbGVuYW1lLWluLWJvZHkiOnRydWV9XX0=","Signature":"1FR73bqB8UtFdq30KYavSgS6XZg=","exist_fname":false,"fname":"aa.txt","key":"temp_384915433_51beba16dd0d45e4be84802890ae64da","result":"ok","stat":"OK","store":"ks3","url":"https://zhstorage.yun.xxx.com/xabfile", "x-kss-newfilename-in-body":true}

    web_reg_save_param("KSSAccessKeyId","LB=KSSAccessKeyId\":\"", "RB=\"", LAST);
    web_reg_save_param("Policy", "LB=Policy\":\"", "RB=\"", LAST);
    web_reg_save_param("Signature", "LB=Signature\":\"", "RB=\"", LAST);
    web_reg_save_param("key", "LB=key\":\"", "RB=\"", LAST);
  //web_reg_save_param("x-kss-newfilename-in-body", "LB=x-kss-newfilename-in-body\":\"", "RB=\}", LAST);
    web_reg_save_param("x-kss-newfilename-in-body", "LB=x-kss-newfilename-in-body\"\:", "RB=\}", LAST);    


    web_url("request", 
        "URL=https://yun.xxx.com/api/files/upload/request?groupid=406896460&parentid=0&size=10&name=aa.txt&parent_path=&checkname=true&store=ks3&method=POST", 
        "Resource=1", 
        "RecContentType=application/json", 
        "Referer=https://yun.xxx.com/drive/group/406896460", 
        "Snapshot=t20.inf", 
        LAST);



    web_add_auto_header("User-Agent", 
      "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36");

    web_add_header("Content-Type", 
        "application/json;charset=utf-8");

    //    web_add_auto_header("Content-Type","multipart/form-data");
    web_add_header("Accept-Encoding", 
        "gzip, deflate");


    web_reg_save_param("newfilename","LB=newfilename\":\"", "RB=\"}", LAST);
    web_submit_data("xabfile", 
        "Action=https://zhstorage.yun.xxx.com/xabfile", 
        "Method=POST", 
        "EncType=multipart/form-data", 
        "RecContentType=text/plain", 
        "Referer=http://yun.xxx.com/drive/group/406896460", 
        "Snapshot=t21.inf", 
        "Mode=HTTP", 
        ITEMDATA, 
        "Name=key", "Value={key}", ENDITEM, 
        "Name=Signature", "Value={Signature}", ENDITEM, 
        "Name=KSSAccessKeyId", "Value={KSSAccessKeyId}", ENDITEM, 
        "Name=Policy", "Value={Policy}", ENDITEM, 
        "Name=x-kss-newfilename-in-body", "Value={x-kss-newfilename-in-body}", ENDITEM, 
        "Name=file", "Value=C:/{filename}", "File=Yes", ENDITEM, 
        LAST);
    web_add_header("Origin",  "https://yun.xxx.com");
    lr_save_string("406896460","id");
    web_custom_request("files_3", 
        "URL=https://yun.xxx.com/api/v3/groups/{id}/files?im_push=1&store=ks3&action=", 
        "Method=POST", 
        "Resource=0", 
        "RecContentType=application/json", 
        "Referer=https://yun.xxx.com/drive/group/{id}", 
        "Snapshot=t22.inf", 
        "Mode=HTTP", 
        "EncType=application/json; charset=UTF-8", 
        "Body={\"groupid\":\"{id}\",\"parentid\":0,\"parent_path\":[],\"name\":\"{filename}1\",\"secure_guid\":\"\",\"size\":10,\"sha1\":\"{newfilename}\",\"csrfmiddlewaretoken\":\"{csrf}\"}",
        LAST);



    return 0;
}

 

代码解析:

web_add_cookie 添加cookie 从而暂时免登录
    web_add_cookie("sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22164ede8841f339-032750c7b54867-68151275-1049088-164ede88421341%22%2C%22%24device_id%22%3A%22164ede8841f339-032750c7b54867-68151275-1049088-164ede88421341%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%7D; DOMAIN=yun.xxx.com");
    web_add_cookie("sajssdk_2015_cross_new_user=1; DOMAIN=yun.xxx.com");
    web_add_cookie("Hm_lvt_088d7d4ca9fd9c419f6d37e55a2732bb=1532999796; DOMAIN=yun.xxx.com");
    web_add_cookie("xabqing_autoLoginV1=1; DOMAIN=yun.xxx.com");
    web_add_cookie("numberOfFailedAttempts=0; DOMAIN=yun.xxx.com");
    web_add_cookie("xab_sid=V02S4fptWYKB4Yj7C3WnpOkUVibg77Y01475a7a40016f157e9; DOMAIN=yun.xxx.com");

 

关联获取第一个请求返回需要的信息

    web_reg_save_param("KSSAccessKeyId","LB=KSSAccessKeyId\":\"", "RB=\"", LAST);
    web_reg_save_param("Policy", "LB=Policy\":\"", "RB=\"", LAST);
    web_reg_save_param("Signature", "LB=Signature\":\"", "RB=\"", LAST);
    web_reg_save_param("key", "LB=key\":\"", "RB=\"", LAST);
  //web_reg_save_param("x-kss-newfilename-in-body", "LB=x-kss-newfilename-in-body\":\"", "RB=\}", LAST);
    web_reg_save_param("x-kss-newfilename-in-body", "LB=x-kss-newfilename-in-body\"\:", "RB=\}", LAST);    

在做脚本时,第三个请求老是不成功,把脚本发送的请求和手动上传的请求对比,发现正常的请求有一行header请求 

Origin: https://yun.xxx.cn

技术分享图片

于是添加一行lr代码:
    web_add_header("Origin",  "https://yun.xxx.com");

最后,代码运行通过,上传成功

技术分享图片

 

loadrunner上传文件到网盘

标签:turn   pts   webkit   CMF   并且   tag   html   utf-8   type   

原文地址:https://www.cnblogs.com/testway/p/9397007.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!