当我们尝试从ipad访问json文件时,我们获得了401状态,其中html内容带有登录页面的url。我们尝试通过在标头中发送用户名和密码来使用基本身份验证,但它没有用。谷歌搜索没有给出任何有用的解决方案。
有人有过类似的问题吗?我只需要使用非浏览器客户端的用户名和密码进行身份验证。
示例节点js代码
var http = require('http');
var username = 'username';
var password = 'password';
var auth = "Basic " + new Buffer(username + ":" + password).toString("base64");
var options = {
host: 'devhome.intranet.example.com',
port: 80,
path: '/app/api/rest/views/category.json',
headers : {
"Authorization" : auth
}
};
http.get(options, function(res) {
console.log("Got response: " + res.statusCode);
console.log(res);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
任何帮助都非常感谢。
THX
答案 0 :(得分:3)
我知道这是一个老问题,但我尝试做类似的事情(.Net客户端访问WebSeal后面的Web服务)。谷歌搜索后没有有用的解决方案。
然而IBM文档给了我一个线索 http://www.ibm.com/support/knowledgecenter/SSPREK_8.0.1.2/com.ibm.isamw.doc_8.0.1.2/wrp_config/task/tsk_submt_form_data_ws.html
基本上,当您从浏览器通过Webseal访问资源时,Webseal会使用登录页面进行响应。输入用户名和密码后,表单数据将提交到/pkmslogin.form。 Webseal还会返回一个cookie,以便后续请求不必再次进行身份验证。
这意味着你需要发送一个POST请求:
必须对/pkmslogin.form进行POST。 POST请求正文必须包含三个字段的字段数据: 用户名,密码,登录表单类型
login-form-type的值必须是" pwd"用于表单登录。 content-length标头必须指明生成的请求主体的长度。
我是使用HttpClient在.Net中完成的。像这样:
using (var httpClient = new HttpClient())
{
// First post the authentication data
var authenticationResult = httpClient.PostAsync("http://webseal/pkmslogin.form",
new FormUrlEncodedContent(
new Dictionary<string, string>()
{
{"username", "user"},
{"password", "pwd"},
{"login-form-type", "pwd"}
}
)
).Result;
// Now access our resource
var webserviceResult = httpClient.GetAsync("http://webseal/webservice").Result;
}
如果这不起作用,您可能需要通过WebSeal获取Cookie返回并每次都发送该Cookie。
答案 1 :(得分:0)
------------------------------------------------------------------------------------
STEP (1)
------------------------------------------------------------------------------------
WEBSEAL URL: https://webseal/pkmslogin.form
METHOD : POST
TYPE : FormUrlEncodedContent
HEADER : Content-Type: application/x-www-form-urlencoded
BODY : login-form-type: pwd, password: XXXXXXXX, username: AAAAAAAA
-------------------------------------------------------------------------------------
200 OK
content-length: 818
content-type: text/html
date: Thu, 28 Jun 2099 19:58:54 GMT
p3p: CP="NON CUR OTPi OUR NOR UNI"
server: WebSEAL/6.0.0.3 (Build 060807)
pragma: no-cache
cache-control: no-cache
Set-Cookie: PD-S-SESSION-ID=2_Uufb+DPeYhDCsF2cjib-aQO6LwMn3VNM1faxbUOGbLKXqwBO; Path=/; Secure
STEP (2)
-------------------------------------------------------------------------------------
ENGAGE URL : https://webseal/engagetv/EngageAgent/MainPage.aspx?windowtype=popup&action_name=startactivity&jobTypeCode=A25&custPkey=0018048794_77
METHOD : GET
HEADER : Set-Cookie: PD-S-SESSION-ID=2_Uufb+DPeYhDCsF2cjib-aQO6LwMn3VNM1faxbUOGbLKXqwBO; Path=/; Secure
200 OK
content-type: text/html; charset=utf-8
date: Thu, 28 Jun 2099 20:09:40 GMT
p3p: CP="NON CUR OTPi OUR NOR UNI"
x-old-content-length: 28754
transfer-encoding: chunked
x-powered-by: ASP.NET
x-ua-compatible: IE=9
cache-control: private
Set-Cookie: Eng5800TicketData=TtyXO3QjJu4qSQAYI6u5rZJr7ZCDRne10O1dt9e5BgPuU02sgszMUKwWOKlSyDVeMnfXyM4XJfe93tv4lQpxgpVKzScTGzK8sIsUiOSX5gHZWtPWcGW+axoaiZcH2+g9to+JvudPAtWvP/7Ikd88qwhCCRLv0KgSBXrpYkh6UlFOe3SDGuor/3/NX9dQbXA9zCqBymhR7W2ZEDYq37lStCKsEOvzV/sUyrAAHGYpptFZzIYIDwuytUpkMi3S6n1ZaDuysxjCjVNvNez5w+M3QF2bzMf625cvlCpJSb1WSnc1ZLbSxMRLXRCrWw/jJKJ1z7c7fPJozwwks/UQyTcRUkdPmwgjiNphT9+c7+LF74k75JAayMYkjR5lD79brFl5oFquck6zyZMCCy8445N98owHOr0vqqtZZaa7qKjZDOaUprx8LD4Qlzn+/YsMEMvgBFDTt1sKdv+SUGkVPi53AzPEkrpmD0H8pdEM6GOS2gXnYZw1tf6hDf3ZDVeGrl9k2ETn6XqDuQoB80af16Ew64TXMHSQgDtur9tndltcp2nqu0Grv04ov6TZKkloAPSZZcQ6ezgivlsASyLupFBKgtcUbC1L92vuf2YVPYA0oBSqOzIsRDe2f3gqNxcBOR9/vmGAhinQ5WzgSo9BkAbGTx/ooqk6kUMbwX2bvKth1SV5oDH5hkrOdnc2pkfpByipTE8lGxvGR1r6PeY7r3WHdfDy8c4HUpLWl3BCKckrmTvIPi2llpkzVRGyWrFVWpb2X/jF+MnGvcdH9Vo7PVvn7seD9TlXXo/ef8RRUmLmykUfxxDgrA1+qru0qu7STDpW4YYY/DPGPVlqg3sX4LRt5w==; Path=/
Eng5800Theme=Default; Path=/
PD-S-SESSION-ID=2_RZOySBlG-n-s7rUo7AiXIWgujUyyWN5674O4AOlW1W3W1-9n; Path=/; Secure
...
...