如何在JavaScript中模仿curl?

时间:2018-08-30 14:48:36

标签: javascript java curl xmlhttprequest

我有一个curl命令,响应正常。但是当我尝试使用Java脚本时,同样的事情并没有成功。

我在dos中运行的卷曲命令:

curl "http://serverip/live/test01/test01_mcs.isml/playlist_high.mpd" -H "Host:actualServer.net" -i

这将返回播放网址。

我正在尝试在JavaScript中模仿的一件事

var xhttp = new XMLHttpRequest();
  xhttp.open("POST", "http://serverip/live/test01/test01_mcs.isml/playlist_high.mpd", true);  
  xhttp.setRequestHeader("Host", "actualServer.net");
  xhttp.setRequestHeader("Access-Control-Allow-Origin", "*");
  xhttp.send();

这会显示错误消息“拒绝设置不安全的标头主机”

我也尝试过http get,但响应相同。

我使用asyncHttpClient.post(url,new ResponseHandler());在Java的AsynHttpClient中进行了尝试。

我也使用asyncHttpClient.post(mContext, url, entity, contentType, new ResponseHandler())尝试了Java的AsynHttpCLient。在这种情况下,我尝试通过实体传递主机,但是没有运气。

我现在没有选择了。任何帮助或建议,我们将不胜感激。

0 个答案:

没有答案