Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

async submit() {…

  1. User

    async submit() { axios.post("http://192.168.11.250:8092/vems/cxfService/external/extReq", { Headers: { 'Access-Control-Allow-Orign': '*' }, Params: { "biz_content": { "car_code": this.cranumshow, "owner": this.name, "visit_name": "访客车辆", "phonenum": this.phonenumber, "reason": "来访", "operator": this.name, "operate_time": this.startdate, "visit_time": { "start_time": this.startdate, "end_time": this.enddate } }, "charset": "utf-8", "command": "ADD_VISITOR_CAR", "device_id": "00000000000000000000001497121A38", "message_id": "8308", "sign": "00000000000000000000000000000000", "sign_type": "MD5", "timestamp": "20230804143800" } }).then(res => { if (res.status === 200) { this.name = ""; this.phonenumber = ""; this.startdate = date.formatDate(Date.now(), 'YYYY-MM-DD HH:mm:ss'); this.enddate = date.formatDate(Date.now(), 'YYYY-MM-DD') + " 17:00:00"; this.carnum = []; this.router.push({ path: '/submitFinish' }) } else { this.router.push({ path: '/submitError' }) } }) },这段代码有什么问题

  2. Assistant

    这段代码的问题是在axios的post请求中,Headers和Params应该是单独的对象,而不应该被包裹在一个大的对象中。

    正确的代码应该是这样的:

    async submit() {
      axios.post("http://192.168.11.250:8092/vems/cxfService/external/extReq", 
        {
          "biz_content": {
            "car_code": this.cranumshow,
            "owner": this.name,
            "visit_name": "访客车辆",
            "phonenum": this.phonenumber,
            "reason": "来访",
            "operator": this.name,
            "operate_time": this.startdate,
            "visit_time": {
              "start_time": this.startdate,
              "end_time": this.enddate
            }
          },
          "charset": "utf-8",
          "command": "ADD_VISITOR_CAR",
          "device_id": "00000000000000000000001497121A38",
          "message_id": "8308",
          "sign": "00000000000000000000000000000000",
          "sign_type": "MD5",
          "timestamp": "20230804143800"
        },
        {
          headers: { 'Access-Control-Allow-Orign': '*' }
        }
      )
      .then(res => {
        if (res.status === 200) {
          this.name = "";
          this.phonenumber = "";
          this.startdate = date.formatDate(Date.now(), 'YYYY-MM-DD HH:mm:ss');
          this.enddate = date.formatDate(Date.now(), 'YYYY-MM-DD') + " 17:00:00";
          this.carnum = [];
          this.$router.push({ path: '/submitFinish' })
        } else {
          this.$router.push({ path: '/submitError' })
        }
      })
    },
    

    在请求中,Headers和Params被分离,并确保Headers是一个独立的对象传递给请求选项。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.