LR: Error -26616: HTTP Status-Code=415 (Unsupported Media Type)怎么解决?

发送json的post请求时,虽然请求脚本中有用到RecContentType=application/json;charset=UTF-8,但是回放时,日志中提示: Error -26616: HTTP Status-Code=415 (Unsupported Media Type) for+请求地址,通过查看请求的包头和发送值,以及抓包工具对比,发现RecContentType参数中定义了响应内容为json,但其实默认发送的居然为:Content-Type: application/x-www-form-urlencoded,这怎么办?

  1. #1

    kity(回复于:2018-09-26 07:09:19)

    解决方法,手工工添加包头参数:
    方法1:如果用web_custom_request发送请求,自带EncType参数,可以直接添加该参数值application/json;charset=UTF-8,即可解决此问题,
    如:
    web_custom_request("placeOrder",
      "URL=http://{IP}/appServer/interface/order/placeOrder",
      "Method=POST",
      "RecContentType=application/json;charset=UTF-8",
      "Snapshot=t1.inf",
      "Mode=HTTP",
      "EncType=application/json;charset=UTF-8",
      "Body={"userId":{userId},"shopId":{shopId},"orderSceneType":1,"orderType":1,"goods":[{"shopId":{shopId},"goodsId":{goodsId}}]}",
      LAST);
    方法2:如果用提交表单(web_submit_data)的方式发送请求,不自带EncType参数,必须手动添加包头,可解决此问题,但会保警告,大概意思是“添加包头后,后续请求将用到”,此警告暂时未影响请求最终效果,可忽略。
    web_add_header("Content-Type","application/json; charset=utf-8");
    web_submit_data("placeOrder",
       "Action=http://{IP}/appServer/interface/order/placeOrder",
       "Method=POST",
       "RecContentType=application/json;charset=UTF-8",
       "Snapshot=t1.inf",
       "Mode=HTML",
       ITEMDATA,
       "Name=data", "Value={userId}", ENDITEM,
       "Name=shopId", "Value={shopId}", ENDITEM,
       "Name=orderSceneType", "Value=1", ENDITEM,
       "Name=orderType", "Value=1", ENDITEM,
       "Name=goods", "Value=[{"shopId":{shopId},"goodsId":{goodsId}}]", ENDITEM,          
       LAST );



我的回答