是否可以使用JavaScript中的POST方法创建和发送类似的HTTP请求?
POST register.jsp HTTP/1.1
Host: hi/iq
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2) Gecko/20021126
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,
video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1
Accept-Language: en-us, en;q=0.50
Accept-Encoding: gzip, deflate, compress;q=0.9
Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66
Keep-Alive: 300
Connection: keep-alive
Content-Type: multipart/form-data; boundary=---------------------------29772313742745
Content-Length: 452
-----------------------------29772313742745
Content-Disposition: form-data; name="name"
J.Doe
-----------------------------29772313742745
Content-Disposition: form-data; name="email"
abuse@spamcop.com
-----------------------------29772313742745
Content-Disposition: form-data; name="file-upload"; filename="test.txt"
Content-Type: text/plain
test data with some high ascii: ¿Como estás?
-----------------------------29772313742745--
我需要的最重要的事情是在最后13行(形成文本数据+表单文件数据)。 数据(文本+文件)将在PHP文件服务器端中检索。 我已经尝试过使用XMLHttpRequest和Formdata,但我无法正常使用它。
最有意义的尝试是:
var fd3 = new FormData();
fd3.append('mode', 'end'); // set $_POST['mode']="end"
fd3.append('file', image.jpg); // set $_FILES['file']=image.jpg
var xhr3 = new XMLHttpRequest();
xhr3.open("POST", "pages/upload_arc3d.php", false);
xhr3.setRequestHeader("Content-type", "multipart/form-data");
xhr3.send(fd3);