node.js请求失败为umts Stick Webserver(huawei)

时间:2014-07-09 13:54:29

标签: node.js rest request

我正试图从huawei umts棒内部网gui获取网站/ xml对象。

我使用libcurl在c中编写了一个包装器,它运行正常。现在我想使用请求将其移植到节点。

当我从控制台调用带有卷曲的网址时,这样:

curl -G "http://192.168.1.1/api/monitoring/status"

我得到了正常的结果:

<?xml version="1.0" encoding="UTF-8"?>
<response>
<ConnectionStatus>901</ConnectionStatus>
<SignalStrength>99</SignalStrength>
<SignalIcon>5</SignalIcon>
<CurrentNetworkType>4</CurrentNetworkType>
<CurrentServiceDomain>3</CurrentServiceDomain>
<RoamingStatus>0</RoamingStatus>
<BatteryStatus></BatteryStatus>
<BatteryLevel></BatteryLevel>
<simlockStatus></simlockStatus>
</response>

当我尝试通过请求呼叫此网站时:

var request = require("request");

var options = {
   url: "http://192.168.1.1/api/monitoring/status"

};

request.get(options, function(error, response, body) {

if(error)
{
    console.log(error);
}
console.log("statusCode: " + response.statusCode);
console.log("statusText: " + response.statusText);
console.log(body);



});

我收到400错误:

statusCode: 400
statusText: undefined
<HTML><HEAD>
<TITLE>IPWEBS - 400 Bad Request</TITLE>
</HEAD>
<BODY><H2>400 Bad Request</H2>
<P>The request generated an error response.</P>
</BODY>
</HTML>

关于这个问题的任何想法?

1 个答案:

答案 0 :(得分:0)

可能是curl正在发送服务器所需的标头。尝试将您的选项更改为:

var options = {
  url: "http://192.168.1.1/api/monitoring/status",
  headers: {
    'User-Agent': 'curl/7.30.0',
    'Accept': '*/*'
  }
}