302文档在使用请求模块连接到API时使用Javascript Nodejs移动了消息

时间:2017-10-27 12:10:04

标签: javascript node.js request

我正在尝试向我的系统使用我的访问详细信息自动登录的API发送POST请求。

我已经设法在Chrome上使用Advanced Rest客户端扩展程序来处理请求,但是当我尝试使用javascript(全新)时,我收到以下错误通知。

我不确定这意味着什么,当我点击响应消息中的链接时显示fatalProfileExpection并提及权限时,该Cookie与我在Chrome应用程序中发送请求的时间完全相同。 / p>

此错误的含义是什么?如何防止它再次发生?

谢谢

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="link">here</a>.</p>
</body></html>

//我的代码

var request = require('request');

//Setting up proxy for Request module
var proxyUrl = "xxx";
var proxiedRequest = request.defaults({'proxy' : proxyUrl});

var headers = {
    'accept': 'application/json',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4',
    'content-type': 'application/json',
    'origin': 'https://xxxxx-online.com',
    'referer': 'https://xxxxx-online.com/x/w/',
    'user-agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'
}

var jar = request.jar();
var cookie = request.cookie('webRedirect=https%3A//xxx-online.com; langChange=en-us; _shibstate_11111111_1111=https%3A%2F%2xxx-online.com%2Fdwsapps-v2%2Fghw%2Fjrpc.aspx; _shibstate_1509087500_8c0c=https%3A%2F%2Fxxx-online.com%2FdwsApps-v2%2Fghw%2Fimg%2Fpassword-hover.png; _shibstate_1509087522_227d=https%3A%2F%2Fxxx-online.com%2Fdwsapps-v2%2Fghw%2Fjrpc.aspx; _shibsession_64656c6f697474652d756b48447470733a2f2f64656c6f697474652d756b2e6d616xxxxxxxxxxxxxxxxxxxx=_8f156f25083c0adc1ec190b6807d5bf7; ASP.NET_SessionId=w2glfje421wggq0clqd2orm4; lang=en-us');
jar.setCookie(cookie, "https://xxx-online.com/x-v2/w/c.aspx");


var options = {
    headers: headers,
    jar: jar,
    url: "https://xxx-online.com/xxx-x/w/x.aspx",
    method: "POST",
    form:  [{"request":"context","sequence":0},{"request":"getUserDetails","sequence":1,"userKey":116487},{"request":"getStateTypes","sequence":2,"type":"S"},{"request":"getStateTypes","sequence":3,"type":"T"},{"request":"getDefStatesTypes","sequence":4},{"request":"getUserRoles","sequence":5},{"request":"getMiscSettings","sequence":6},{"request":"getRegions","sequence":7,"userGroupKey":51424,"returnAll":1},{"request":"getRegionSites","sequence":8,"userGroupKey":51424},{"request":"roomFlags","sequence":9},{"request":"getFixtureClasses","sequence":10},{"request":"getProviders","sequence":11,"collectionKey":-1,"fixtureFlag":0},{"request":"getVisitorTypes","sequence":12},{"request":"deskFlags","sequence":13},{"request":"getConferenceTypes","sequence":14},{"request":"getCompanyLogo","sequence":15,"paramName":"CompanyLogo"},{"request":"roomCollections","sequence":16,"deskingFlag":1,"personalCollection":1,"date":"2017-09-14"},{"request":"roomCollections","sequence":17,"deskingFlag":1,"personalCollection":0,"date":"2017-09-14"},{"request":"getFavouriteRooms","sequence":18}]
}

request(options, function(error, response, body) {
    console.log(body);
});

1 个答案:

答案 0 :(得分:0)

302本身并不是错误,更多的是通知您,您要查找的内容已移至其他位置。 如果上面的html是您得到的响应,但似乎他们已经错误地实现了302,因为

<p>The document has moved <a href="link">here</a>.</p>

HTML应该告诉你href中的新位置。

您可以在此处阅读有关HTTP 302代码的更多信息https://en.wikipedia.org/wiki/HTTP_302