Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过JavaScript将XML发布到RESTAPI?_Javascript_Xml_Post - Fatal编程技术网

如何通过JavaScript将XML发布到RESTAPI?

如何通过JavaScript将XML发布到RESTAPI?,javascript,xml,post,Javascript,Xml,Post,我试图通过JavaScript将XML发布到RESTAPI 请求数据如下所示: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <EditGame xmlns="http://blahblahblah.com" > <playerCount>2</playerCount> <score>2621440</score> </EditGame> 希望这

我试图通过JavaScript将XML发布到RESTAPI

请求数据如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<EditGame xmlns="http://blahblahblah.com" >
<playerCount>2</playerCount>
<score>2621440</score>
</EditGame>

希望这有意义。

您可以将XML作为简单字符串传递

xhr.open('POST',URLgameUpdateAction);
xhr.setRequestHeader('Content-type','application/x-www.form-urlencoded');
xhr.send("\
  <?xml version='1.0' encoding='UTF-8' standalone='yes'?>\
  <EditGame xmlns='http://blahblahblah.com'>\
  <playerCount>2</playerCount>\
  <score>2621440</score>\
  </EditGame>\
");
xhr.open('POST',URLgameUpdateAction);
setRequestHeader('Content-type','application/x-www.form-urlencoded');
xhr.send(“\
\
\
2\
2621440\
\
");
xhr.open('POST',URLgameUpdateAction);
xhr.setRequestHeader('Content-type','application/x-www.form-urlencoded');
xhr.send("\
  <?xml version='1.0' encoding='UTF-8' standalone='yes'?>\
  <EditGame xmlns='http://blahblahblah.com'>\
  <playerCount>2</playerCount>\
  <score>2621440</score>\
  </EditGame>\
");