鍍金池/ 問答/PHP  Android  HTML/ js如何發(fā)起Method=CONNECT的http請(qǐng)求

js如何發(fā)起Method=CONNECT的http請(qǐng)求

1.http協(xié)議中支持以下方法

clipboard.png

2.XMLHttpRequest不支持connect的method

xmlHttp=null;
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Opera, etc.
  xmlHttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlHttp!=null)
  {
  xmlHttp.open("CONNECT", "http://www.w3school.com.cn/example/xdom/note.xml", false);
  xmlHttp.send(null);
  xmlDoc=xmlHttp.responseText;

  xmlHttp.open("CONNECT", "http://www.w3school.com.cn/example/xdom/demo_dom_http.asp", false);
  xmlHttp.send(xmlDoc);
  document.write(xmlHttp.responseText);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }

clipboard.png

3.問題:JavaScript或php等語言中,如何發(fā)起method=connect的http請(qǐng)求?

回答
編輯回答
笨笨噠

CONNECT 方法是給代理用的,比如你設(shè)置HTTPS代理,那個(gè)發(fā)給代理服務(wù)器的就是 CONNECT 方法

2017年8月29日 03:36
編輯回答
懷中人

個(gè)人感覺可能是因?yàn)?code>connect是一個(gè)雙向傳輸?shù)姆椒?,?code>ajax這種異步的請(qǐng)求沒辦法做到雙向數(shù)據(jù)傳輸(只能在發(fā)起請(qǐng)求時(shí)傳輸數(shù)據(jù)

如果要實(shí)現(xiàn)類似的操作,我覺得你可以考慮使用web scoket吧。

2018年1月24日 04:30
編輯回答
檸檬藍(lán)

謝邀。你也知道XMLHttpRequest屬于運(yùn)行環(huán)境提供的Web API,不支持CONNECTTRACK,TRACE。所以如果你是問瀏覽器怎么發(fā),那是發(fā)不出去的。如果你是問JavaScript怎么發(fā),可以從服務(wù)器上發(fā),比如nodejs

2017年8月21日 02:42