Ausführen einer HTTP-Anforderung mithilfe von Sockets
Ich versuche eine zu machenHTTP request
mit Steckdosen. Mein Code lautet wie folgt:
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();
}
}
Wenn ich jetzt den obigen Code ausführe, passiert nichts, wohingegen wenn ich meinen eingeberequest_url
Im Browser bekomme ich eine Benachrichtigung von Snarl, die das sagtApplication Registered
und die Antwort, die ich vom Browser erhalte, ist
SNP/2.0/0/OK/556
Die Antwort, die ich von meinem Code erhalte, istSNP/3.0/107/BadPacket
.
Also, was ist los mit meinem Code.