在使用httpWebRequest时需要帮助 [英] Need help using httpWebRequest

查看:69
本文介绍了在使用httpWebRequest时需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string ipadres = proxyconnection[0];
            int port = Convert.ToInt32(proxyconnection[1]);
            string URL = proxyconnection[2];



            HttpWebRequest request = HttpWebRequest.Create(URL) as HttpWebRequest;
            request.Proxy = new WebProxy(ipadres, port);
            request.Method = "POST";
            request.ContentLength = 0;
            request.UserAgent = "Someone";
            request.KeepAlive = true; 
            
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream ReceiveResponse = response.GetResponseStream();

            StreamReader readResponse = new StreamReader(ReceiveResponse, Encoding.UTF8);

            response.Close();
            readResponse.Close();



但是,这会给我一个错误404,而页面却很少.或在wordpress上.张贴方法是禁止的.似乎根本无法正常工作.我在做什么错?



This though, gives me either Error 404 while few pages exist. or on wordpress. Post method is forbidden. Can''t seem to get it working at all. What am I doing wrong?

推荐答案

仅以您Ultimatemafia.nl网站为例,这是我尝试访问该网站时发生的事情:

首先,Firefox执行Get.这将发送回一个标头,该标头将cookie设置到系统,然后重定向到index.php.

然后使用get请求并传回原始cookie,以请求Index.php.然后,加载html.

如果我有密码,它将运行一个post到index.php?pagina = inloggen,以传递登录名和传递值并传递已发送的cookie.这将设置一系列新的Cookie,然后最终将html传递给play.php.尽管如此.

因此,要编写一些与此相关的内容,首先,您必须使用凭据运行登录到登录"页面.然后,您将获得响应流,并且将包含该信息.获取正确信息的另一个重要部分是确保在HTTPWebRequest中也设置了引荐来源.

如果要允许他们输入任何类型的URL,则基本上必须编写一个完整的Internet浏览器.但是,如果将其限制为特定站点,并且您确切知道这些站点的工作方式,则可以很容易地编写代码以连接到这些站点.
just as an example with your ultimatemafia.nl site, here''s what happens when I try to go to it:

First, Firefox does a Get. That sends back a header that sets a cookie to the system and then redirects to index.php.

Index.php is then requested using a get and passing back the original cookie. This then, loads the html.

If, I then have a password, it runs a Post to index.php?pagina=inloggen passing in a login and pass value and passing the cookies that were sent. This sets a new series of cookies and then passes in the html finally...though of play.php.

So to write something to connect to that, first you have to run a Post to the log in page with the credentials. Then, you get the response stream and that will have the information. The other important part of getting the right information is making sure that the referer is also set in the HTTPWebRequest.

You would basically have to write a full internet browser if you want to allow them to put in any type of URL. But, if you limit it to specific sites and if you know exactly how those sites work, you can write code pretty easily to connect to the sites.


请参见此处:
see here:Redirect HTTP Post[^]

My answer was for wordpress. The techniques you use and the information your provide in the header is dependent on the web page.

To find out that information, you can use various add-ins like HttpFox in FireFox and then actually trace the process for actually getting to the pages.


我认为可以将LOIc的http Flooder与进行一些调整即可.在C ++中应该看起来像这样
I think using the http flooder from LOIc with a few adjustments should work. in C++ should look something like this
holc_http_common.hpp:

#ifndef _HOLC_HTPP_COMMON_HPP
#define _HOLC_HTPP_COMMON_HPP
#include "../common/holc_common.hpp"

#ifdef HOLC_VERSION_WIN32
#include <WinSock2.h>
#define HOLCSOC SOCKET
#define TCP 6
#pragma comment(lib, "WS2_32.lib")
#elif defined(HOLC_VERSION_LINUX)
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/unistd.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define HOLCSOC int
#define TCP 0
#define closesocket close
#endif

#endif /* _HOLC_HTPP_COMMON_HPP */


holc_http.hpp:

#ifndef _HOLC_HTTP_HPP
#define _HOLC_HTTP_HPP

#include "../common/holc_common.hpp"
#include "holc_http_common.hpp"

namespace HOLC
{
	namespace HTTP
	{
		enum HOLC_MethodType { POST, GET };
		class HOLC_HttpRequest
		{
		public:
			HOLC_HttpRequest(std::string Header);
			HOLC_HttpRequest(HOLC_MethodType Type, std::string exData);
			~HOLC_HttpRequest();

			void WriteHeader(std::string headerData);
			void WriteData(char * requestData);
			void SetTarget(std::string IP, short Port);
			void Finalize();

			int  getContentSize();
		private:
			bool		bDone, bTrgt;
			sockaddr_in	aTrgt;
			std::string httpHeader;
			std::string httpData;
			std::string reString;
		};

		std::string HOLC_getMethodStr(HOLC_MethodType Type);
	}
}

#endif /* _HOLC_HTTP_HPP */


holc_http.cpp:

#include "holc_http.hpp"

namespace HOLC
{
	namespace HTTP
	{
		std::string HOLC_getMethodStr(HOLC_MethodType Type)
		{
			switch(Type)
			{
			case POST: return "POST";
			case GET:  return "GET";
			default:   return "ERROR";
			}
		}

		HOLC_HttpRequest::HOLC_HttpRequest(std::string Header) : bDone(false), bTrgt(false)
		{
			WriteHeader(Header);
		}

		HOLC_HttpRequest::HOLC_HttpRequest(HOLC_MethodType Type, std::string exData) : bDone(false), bTrgt(false)
		{
			std::string type = HOLC_getMethodStr(Type);
			if(!strcmp(type.c_str(), "ERROR"))
				throw "HOLC_FATAL_EXCEPTION: HOLC_HttpRequest -> Invalid MethodType";
			WriteHeader(type + " /" + exData + " HTTP/1.1");
		}

		HOLC_HttpRequest::~HOLC_HttpRequest()
		{
			if(!bDone)
				Finalize();
		}

		void HOLC_HttpRequest::WriteHeader(std::string headerData)
		{
			if(!bDone)
				this->httpHeader += headerData + "\r\n";
		}

		void HOLC_HttpRequest::WriteData(char * requestData)
		{
			if(!bDone)
				this->httpData += requestData;
		}

		void HOLC_HttpRequest::SetTarget(std::string IP, short Port)
		{
			if(!bTrgt)
			{
				memset(&this->aTrgt, 0, sizeof(this->aTrgt));
				this->aTrgt.sin_family = AF_INET;
				this->aTrgt.sin_addr.s_addr = inet_addr(IP.c_str());
				this->aTrgt.sin_port = htons(Port);
				bTrgt = true;
			}
		}

		void HOLC_HttpRequest::Finalize()
		{
			if(!bTrgt)
				throw "HOLC_FATAL_EXCEPTION: HOLC_HttpRequest::Finalize() Target not set.";

			this->reString = this->httpHeader + "\r\n" + this->httpData;
			this->httpHeader.clear(); this->httpData.clear();
			HOLCSOC connection = socket(AF_INET, SOCK_STREAM, TCP);
			connect(connection, (sockaddr*)&this->aTrgt, sizeof(this->aTrgt));
			send(connection, this->reString.c_str(), this->reString.size(), 0);
			closesocket(connection);
			this->bDone = true;
		}

		int HOLC_HttpRequest::getContentSize()
		{
			return this->httpData.size();
		}
	}
}


这篇关于在使用httpWebRequest时需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆