简体   繁体   中英

Required String parameter 'graphName' is not present

var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        console.log("excel download");
      }
    };
    xhttp.open("POST", "exportGraphExcel", true);
    xhttp.setRequestHeader("Content-type", "application/msexcel");
    xhttp.send('graphName=graphakki');

It gives 400 status in browser. If Content-type is changed to "application/x-www-form-urlencoded" then request is accepted.

The content type in a request header is the content of what you're sending . You're not sending an Excel file, you're requesting an excel file.

When you send the "application/x-www-form-urlencoded" content type header, you're telling the server that your parameters must be read in the URL ( this is the standard way ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM