目前在做一個驗證帳號可用性的node模塊,使用 request 發送POST請求到驗證伺服器, 如果狀態碼是 200 就代表驗證成功,403 就代表驗證失失敗。 可是明明帳號密碼就對了 ,卻一直回傳403, 但是我使用C#做的帳號驗證程式卻回傳200狀態碼, 各位大神知道問題在哪裡馬? 求解
POST 請求訊息 : Url : https://loader.joduska.me/login/alanting850420 Method : POST Body : p=72248a5b6a849968285a25a3962be092 Content-Type : application/x-www-form-urlencoded
node 代碼 :
var authServer = "https://loader.joduska.me/login/alanting850420";
var buffer = new Buffer("p=72248a5b6a849968285a25a3962be092");
request({
method : 'POST',
uri : authServer,
body : buffer,
headers : [{
name : 'content-type',
value : 'application/x-www-form-urlencoded'
}]
},function(err,res,body){
if (err)
return;
if (res.statusCode == 403)
socket.emit('AuthFailed');
else
{
socket.emit('AuthSucceed');
authed = true;
}
})
C# 代碼 :
var data = "p=72248a5b6a849968285a25a3962be092";
var dataBytes = Encoding.UTF8.GetBytes(data);
var wr = HttpWebRequest.Create("https://joduska.me/login/" + WebUtility.UrlEncode("alanting850420"));
wr.Timeout = 2000;
wr.ContentLength = dataBytes.Length;
wr.Method = "POST";
wr.ContentType = "application/x-www-form-urlencoded";
try
{
var dataStream = wr.GetRequestStream();
dataStream.Write(dataBytes, 0, dataBytes.Length);
dataStream.Close();
wr.GetResponse();
return true;
}
catch (WebException ex)
{
if ((int)((HttpWebResponse)ex.Response).StatusCode == 403)
{
return false;
}
return false;
}
个人觉得你得从服务器端获取数据来做分析,因为浏览器的模拟请求也同样403,没有运行过你的c#代码,不确定是真的可以返回200.
Remote Address:141.101.127.101:443
Request URL:https://loader.joduska.me/login/alanting850422
Request Method:POST
Status Code:403 Forbidden
Response Headers
cf-ray:1d19b20f571e0293-SJC
content-encoding:gzip
content-type:text/plain
date:Sat, 04 Apr 2015 02:48:40 GMT
server:cloudflare-nginx
status:403 Forbidden
vary:Accept-Encoding
version:HTTP/1.1
Request Headers
:host:loader.joduska.me
:method:POST
:path:/login/alanting850422
:scheme:https
:version:HTTP/1.1
accept:*/*
accept-encoding:gzip, deflate
accept-language:zh-CN,zh;q=0.8,en;q=0.6
cache-control:no-cache
content-length:35
content-type:application/x-www-form-urlencoded
cookie:__cfduid=d52e63c82f5afc1ede0c81bee94ba19dd1428114297
origin:chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm
pragma:no-cache
ra-sid:2A784A65-20141203-061323-303f51-964286
ra-ver:2.9.0
user-agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36
Form Data
view source
view URL encoded
p:72248a5b6a849968285a25a3962be092
@rjiang21 源碼6小時前有修改 好像是除了200還會返回一個密碼的hash
https://github.com/LeagueSharp/LeagueSharp.Loader/commit/03bfca62a698b945718380415b18e648c25fc8cd
var request = require(‘request’);
var headers = { 'Content-Type’: ‘application/x-www-form-urlencoded’ }; var buffer = new Buffer(“p=72248a5b6a849968285a25a3962be092”);
// Configure the request var options = { url: 'https://loader.joduska.me/login/alanting850420’, method: 'POST’, headers: headers, body: buffer };
// Start the request request(options, function(error, response, body) { if (!error && response.statusCode == 200) { // Print out the response body console.log(body); } else { console.log(response.statusCode ); } }); 完成,好像是你的用户名写错了