如何发出GET URL请求(同一服务器)

时间:2017-10-20 10:21:20

标签: node.js express

我正在运行快递4应用程序(nodejs)

在其中一个服务器端函数中,我想发出一个GET请求来获取一些值。 GET请求URL指向同一服务器。为什么这不起作用,我该如何使其发挥作用?

额外信息:

  • http://mywebsite/是我的网络应用的主要域名。
  • http://mywebsite/abc/getData/16-10-2017可在浏览器中使用
  • 面向外部的请求工作正常(因此请求设置没有问题)

    library(data.table)
    df$c <- shift(df$b, 1)
    
    df
    #    a      b      c
    #1   1    red   <NA>
    #2   2 yellow    red
    #3   3   blue yellow
    #4   4  green   blue
    #5   5 yellow  green
    #6   6 purple yellow
    #7   7   blue purple
    #8   8  green   blue
    #9   9 yellow  green
    #10 10 purple yellow
    

错误代码:

function testing(){
  dateVAL="16-10-2017"
  var requestURL = "http://mywebsite/abc/getData/" + dateVAL  


  request({
      url: requestURL,
      method:"GET",
  },
  function(error,response,body){
    console.log("error")
    console.log(error)
    console.log("response")
    console.log(response)
    console.log("body")
    console.log(body)
  });
}

1 个答案:

答案 0 :(得分:0)

找到解决方案,修改我的地址:

var requestURL = "http://mywebsite/abc/getData/" + dateVAL

为:

var requestURL = "http://localhost/abc/getData/" + dateVAL

相关问题