我正在尝试使用Tor-Server作为代理HttpWebRequest,我的代码如下所示:
HttpWebRequest request;
HttpWebResponse response;
request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
request.Proxy = new WebProxy("127.0.0.1:9051");
response = (HttpWebResponse)request.GetResponse();
response.Close();
Run Code Online (Sandbox Code Playgroud)
它与"正常"代理完美配合,但使用Tor我在调用时遇到异常
GetResponse() with Status = ServerProtocolViolation. The message is (in German...):Message = "Der Server hat eine Protokollverletzung ausgeführt.. Section=ResponseStatusLine"
在.NET中,是否可以将原始HTTP请求转换为HTTPWebRequest对象?
我确信.NET在内部做到了.知道.NET的哪个部分实际上正在处理这个问题?我可以调用它还是有任何允许原始HTTP连接的外部库?
我正在尝试HTTP request使用套接字.我的代码如下:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class test
{
public static void Main(String[] args)
{
string hostName = "127.0.0.1";
int hostPort = 9887;
int response = 0;
IPAddress host = IPAddress.Parse(hostName);
IPEndPoint hostep = new IPEndPoint(host, hostPort);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(hostep);
string request_url = "http://127.0.0.1/register?id=application/vnd-fullphat.test&title=My%20Test%20App";
response = sock.Send(Encoding.UTF8.GetBytes(request_url));
response = sock.Send(Encoding.UTF8.GetBytes("\r\n"));
bytes = sock.Receive(bytesReceived, bytesReceived.Length, 0);
page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
Console.WriteLine(page);
sock.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我执行上面的代码时没有任何反应,而当我进入我request_url的浏览器时,我收到来自Snarl的通知,说 …