HTML5 level2の学習範囲としてXMLHttpRequestを学習してます、リクエストを要求するサーバがないとレスポンスやイベントの確認が行えないのでNode.jsでサーバを構築しました。
前回の範囲のWebSockectでサーバ構築しています、一応問題はないかと思いXMLHttpRequestの学習に利用しています。
サーバと接続はできましたがリクエストを送ると
"VM64:1 POST http://localhost:8080/ 426 (Upgrade Required)"
とエラーが出て処理が行えません、プロトコルをアップデートしていないことが原因らしいですが
今の僕では全然理解できません。
どうかお力をお借しいただけないでしょうか?
下にサーバ立ち上げ時のコードとXHRの処理を載せます。
サーバ
var
1var wss = new WebSokectServer({ 2 host: '0.0.0.0', 3 port: 8080 4}); 5wss.on('connection',function(ws){ 6 ws.on('mesage',function(message){ 7 console.log("require: %s",message); 8 ws.send(message); 9}); 10});
クライアント
var
1 2xhr.onreadystatechange = function(){ 3 switch(xhr.readyState){ 4 case 0: 5 console.log('Uninitialzed!'); 6 break; 7 case 1: 8 console.log('loading...'); 9 break; 10 case 2: 11 console.log('loadend'); 12 break; 13 case 3: 14 console.log('interactive...'+xhr.response.length+'byte'); 15 break; 16 case 4: 17 if(xhr.status == 200 || xhr.status == 304){ 18 console.log('COMPLETE!:'+data); 19 } else{ 20 console.log('Failed. HttpStatus:'+xhr.statusText); 21 } 22 break; 23 } 24} 25 26xhr.open('POST','http://localhost:8080',false); 27xhr.setRequestHeader('Context-Type','application/x-www-form-urlencoded'); 28xhr.abort();
バーション
node - 8.6.0
npm - 5.3.0
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー