简体   繁体   English

Node.js请求获取VAST标签

[英]Node.js request GET a VAST tag

I am trying to make a GET request to a certain url that returns a VAST tag. 我正在尝试向某个返回VAST标记的网址发出GET请求。 When I curl the url, curl -v 'http://a.host.for.vasttag.com/foo/ad.jsp?fooid=someidhere' I receive normal html like this: 当我卷曲网址时, curl -v 'http://a.host.for.vasttag.com/foo/ad.jsp?fooid=someidhere'我会收到像这样的普通html:

<script type="text/javascript" src="foobar.js"></script><script type="text/javascript">var FOO_customization = {"account":"foo1","playerid":"foo1232","inapp":"true","domain":"foodomain.com"}</script><script type="text/javascript" id="exampleBanner" src="http://this.is.net/banner/LATEST/inbanner.min.js"></script>

I would like to receive the same response in my node.app, but I only receive this: 我想在我的node.app中收到相同的响应,但是我只收到以下信息:

<?xml version="1.0" encoding="utf-8"?> <VAST version="3.0"></VAST>

What did I do wrong? 我做错了什么? Here is my code: 这是我的代码:

var http = require('http')

var options = {
  method : 'GET',
  host: 'a.host.for.vasttag.com',
  port: 80,
  path: '/foo/ad.jsp?fooid=someidhere',
  headers: {'Content-Type': 'text/html'},
}

http.get(options, function(res) {
  console.log("Got response: " + res.statusCode)
  res.on("data", function(chunk) {
    console.log(chunk)
  })
}).on('error', function(e) {
  console.log("Got error: " + e.message)
})

It may seem a bit weird, but some VAST engines won't give a response unless you specify a User-Agent 似乎有些怪异,但是除非您指定User-Agent否则某些VAST引擎不会给出响应

This is what my VAST server guys told me. 这是我的VAST服务器人员告诉我的。

And User-Agent is a mandatory header for protocol in order to obtain a VAST response (it's used in ad targeting). 而且User-Agent是协议的必需标头,以便获取VAST响应(用于广告定位)。 That is why without User-Agent you got an empty response. 这就是为什么没有User-Agent时您会得到空响应的原因。

Try adding 尝试添加

var options = {
    method: 'GET',
    host: 'a.host.for.vasttag.com',
    port: 80,
    path: '/foo/ad.jsp?fooid=someidhere',
    headers: {
      'Content-Type': 'text/html',
      'User-Agent': 'Fiddler' //here
    }
};

PS: I used Fiddler cos it was the shortest and it worked. PS:我用了Fiddler cos,因为它是最短的,而且有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM