[已解決] request POST請求總是403
发布于 9 年前 作者 NitroXenon 16520 次浏览 最后一次编辑是 8 年前 来自 问答

目前在做一個驗證帳號可用性的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;
}
13 回复

看下post的数据是json格式还是form格式?

真的沒大神知道原因嗎?

个人觉得你得从服务器端获取数据来做分析,因为浏览器的模拟请求也同样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

服务端有两种验证方式base 和 digest 如果是digest验证要做处理才行。

我运行你的C#代码,p应该是password吧?我把里面的数值修改后,依然200?

@rjiang21 p是password的md5 要帳密正常才會返回200

不知道是不是因為經過 cloudflare 所以會失敗…

@NitroXenon 你再试试你的C#吧,我把密码改掉了依然返回200.。。。

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 ); } }); 完成,好像是你的用户名写错了 2015-04-03_23-28-17.png

@rjiang21 可以了 感謝大神 話說原來昨天服務器更新了 更新前是403的說XD

回到顶部