<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[recv HTTP problem]]></title><description><![CDATA[<p>Hey. ein bessere Titel ist mir leider nicht eingefallen xD.</p>
<p>Naja, auf jeden fall hab ich mir ne kleine Klasse aufgebaut, ich poste mal nur die relevante Funktion, da ich keinen Spoiler finden kann xD.</p>
<p>Leider kann ich die Seite, dich ich als Vorlage genommen habe nicht mehr finden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":-("
      alt="😞"
    /></p>
<p>Erstaml etwas erklärt. Ich empfange erst den HTTP header. Anhand des headers wird dann ausgelesen, wie der reste empfangen wird, per content-size, chunked, oder per no given size.</p>
<p>Wird der rest per chunked empfangen, habe im empfangenen quelltext immer mal wider Zeichen wie diese:</p>
<pre><code>ÌÌÌÌÌÌÌÌ
</code></pre>
<p>Ich kann mir nicht erklären, wo diese her kommen.<br />
Die einzige plausieble erklärung für mich wäre, dass das der Hex code ist, welcher ja die größe des zu empfangenen parts darstellt.</p>
<p>Nun die Frage, wie bekomme die diese raus ?</p>
<p>hier mein Code :</p>
<pre><code class="language-cpp">bool WebTCP::navigate(std::string url, std::string post) 
{
	std::string oldUrl = url;
	removeHttp(url);
	std::string hostname = RemoveHostname(url);
	hostent* phe = gethostbyname(hostname.c_str());

	if(phe == NULL)
	{
		std::cout &lt;&lt; &quot;Host konnte nicht aufgelöst werden&quot; &lt;&lt; std::endl;
		return false;
	}

	if(phe-&gt;h_addrtype != AF_INET)
	{
		std::cout &lt;&lt; &quot;Ungueltiger Adresstyp!&quot; &lt;&lt; std::endl;
		return false;
	}

    if(phe-&gt;h_length != 4)
    {
        std::cout &lt;&lt; &quot;Ungueltiger IP-Typ!&quot; &lt;&lt; std::endl;
		return false;
    }

	int Socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

    if(Socket == -1)
    {
        std::cout &lt;&lt; &quot;Socket konnte nicht erstellt werden!&quot; &lt;&lt; std::endl;
		return false;
    }

    sockaddr_in service;
    service.sin_family = AF_INET;
    service.sin_port = htons(80); // Das HTTP-Protokoll benutzt Port 80

    char** p = phe-&gt;h_addr_list; // p mit erstem Listenelement initialisieren
    int result; // Ergebnis von connect
    do
    {
        if(*p == NULL) // Ende der Liste
        {
            std::cout &lt;&lt; &quot;Verbindung fehlgschlagen!&quot; &lt;&lt; std::endl;
			return false;
        }

        service.sin_addr.s_addr = *reinterpret_cast&lt;unsigned long*&gt;(*p);
        ++p;
        result = connect(Socket, reinterpret_cast&lt;sockaddr*&gt;(&amp;service), sizeof(service));
    }
    while(result == -1);

    std::cout &lt;&lt; &quot;Verbindung erfolgreich!&quot; &lt;&lt; std::endl;

	std::string packet;

	if(post.length() &lt; 1)
	{
		packet = &quot;GET &quot; + url + &quot; HTTP/1.1\n&quot;;
		packet += &quot;Host: &quot; + hostname + &quot;\n&quot;;
		packet += &quot;User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.4) Gecko/20100611 AskTbUT2V5/3.8.0.12304 Firefox/3.6.4\n&quot;;
		packet += &quot;Accept: text/javascript, text/html, application/xml, text/xml, */*\n&quot;;
		packet += &quot;Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n&quot;;
		if(referer.length() &gt; 1)
			packet += &quot;Referer: &quot; + referer + &quot;\n&quot;;
		packet += &quot;Keep-Alive: 115\n&quot;;
		packet += &quot;Connection: keep-alive\n\n&quot;;
	}else{

		std::ostringstream Str;
		Str &lt;&lt; post.length();
		std::string postSize(Str.str());	

		packet = &quot;POST &quot; + url + &quot; HTTP/1.1\n&quot;;
		packet += &quot;Host: &quot; + hostname + &quot;\n&quot;;
		packet += &quot;User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.4) Gecko/20100611 AskTbUT2V5/3.8.0.12304 Firefox/3.6.4\n&quot;;
		packet += &quot;Accept: text/javascript, text/html, application/xml, text/xml, */*\n&quot;;
		packet += &quot;Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n&quot;;
		if(referer.length() &gt; 1)
			packet += &quot;Referer: &quot; + referer + &quot;\n&quot;;
		packet += &quot;Keep-Alive: 115\n&quot;;
		packet += &quot;Connection: keep-alive\n&quot;;
		packet += &quot;Content-Type: application/x-www-form-urlencoded\n&quot;;
		packet += &quot;Content-Length: &quot; + postSize;
		packet += &quot;\n\n&quot; + post;
	}
	std::fstream fout(&quot;header&quot;, std::ios::binary | std::ios::out);
    if(!fout)
    {
        std::cout &lt;&lt; &quot;Could Not Create File!&quot; &lt;&lt; std::endl;		
        return false;
    }	
	fout.write(packet.c_str(), packet.length());

	std::cout &lt;&lt; packet &lt;&lt; std::endl; 
	header.clear();

	try
    {		
        SendAll(Socket, packet.c_str(), packet.size());

        int code = 100; // 100 = Continue       
		std::string line;
		std::string msg;
		// HTTP/1.1 200 OK
		boost::regex PatternFirstline(&quot;[^\w]+ ([0-9]+) ([^\n]+)&quot;);		
		boost::cmatch match;	

		std::cout &lt;&lt; &quot;recv header&quot; &lt;&lt; std::endl;

        while(code == 100)
        {
            GetLine(Socket, line);			
			if(boost::regex_match(line.c_str(), match, PatternFirstline))
			{
				code = atof(match[1].str().c_str());
				msg = match[2];
			}else{
				if(line.length() &gt; 1)
				{
					std::cout &lt;&lt; &quot;unerwarteter Fehler!&quot; &lt;&lt; std::endl;
					return false;
				}
			}
            if(code == 100)
            {
                GetLine(Socket, line); // Leere Zeile nach Continue ignorieren				
            }
        }
        std::cout &lt;&lt; &quot;Msg: &quot; &lt;&lt; msg &lt;&lt; std::endl;

        if(code == 500)
        {
            std::cout &lt;&lt; &quot;Error #&quot; &lt;&lt; code &lt;&lt; &quot; - &quot; &lt;&lt; msg &lt;&lt; std::endl;			
            return false;
        }

        bool chunked = false;
        const int noSizeGiven = -1;
        int size = noSizeGiven;

		boost::regex PatternLine(&quot;([^:]+): ([^\n]+)&quot;);	

        while(true)
        {
            GetLine(Socket, line);			
			if(line.find(&quot;\r&quot;) != std::string::npos &amp;&amp; line.length() &lt; 2) // Header zu Ende?
            {
                break;
            }
			if(line.length() &gt; 1)
			{
				if(boost::regex_match(line.c_str(), match, PatternLine))
				{
					if(match[1].str().find(&quot;Content-Length&quot;) != std::string::npos)
					{
						size = atof(match[2].str().c_str());
					}
					else if(match[1].str().find(&quot;Transfer-Encoding&quot;) != std::string::npos)
					{
						if(match[2].str().find(&quot;chunked&quot;) != std::string::npos)
							chunked = true;
					}
					else if (match[1].str().find(&quot;Location&quot;) != std::string::npos)
					{
						if(match[2].str().c_str()[0] == '/')
							hostname += match[2];
						else
							hostname = match[2];
						location = hostname;
						std::cout &lt;&lt; &quot;Location found: &quot; &lt;&lt; hostname &lt;&lt; std::endl;
						if (autoLocation)
						{
							navigate(hostname);
							closesocket(Socket);
							return true;
						}
					}
				}
				else
				{
					std::cout &lt;&lt; &quot;unerwarteter Fehler!&quot; &lt;&lt; std::endl;
					return false;
				}
			}
        }
		// if we come to here no location was found !
		//location.clear();

        int recvSize = 0; // Empfangene Bytes insgesamt
        char buf[1024];
        int bytesRecv = -1; // Empfangene Bytes des letzten recv

		body.clear();
		std::string tmpBody;

        if(size != noSizeGiven) // Wenn die Größe über Content-length gegeben wurde
        {
            std::cout &lt;&lt; &quot;0%&quot;;
            while(recvSize &lt; size)
            {
                if((bytesRecv = recv(Socket, buf, sizeof(buf), 0)) &lt;= 0)
                {
                    std::cout &lt;&lt; &quot;Error while resiving via content-length&quot; &lt;&lt; std::endl;
					return false;
                }
                recvSize += bytesRecv;
				tmpBody += buf;
                std::cout &lt;&lt; &quot;\r&quot; &lt;&lt; recvSize * 100 / size &lt;&lt; &quot;%&quot; &lt;&lt; std::flush; // Mit \r springen wir an den Anfang der Zeile
            }
        }
        else
        {
            if(!chunked)
            {
                std::cout &lt;&lt; &quot;Downloading... (Unknown Filesize)&quot; &lt;&lt; std::endl;
                while(bytesRecv != 0) // Wenn recv 0 zurück gibt, wurde die Verbindung beendet
                {
                    if((bytesRecv = recv(Socket, buf, sizeof(buf), 0)) &lt; 0)
                    {
                    std::cout &lt;&lt; &quot;Error while resiving via unknow size&quot; &lt;&lt; std::endl;
					return false;
                    }
                    tmpBody += buf;
                }
            }
            else
            {
                std::cout &lt;&lt; &quot;Downloading... (Chunked)&quot; &lt;&lt; std::endl;
                while(true)
                {
                    std::stringstream sstream;
                    GetLine(Socket, sstream);
                    int chunkSize = -1;
                    sstream &gt;&gt; std::hex &gt;&gt; chunkSize; // Größe des nächsten Parts einlesen					
                    if(chunkSize &lt;= 0) // Wenn 0 komplett !
                    {
                        break;
                    }
                    std::cout &lt;&lt; &quot;Downloading Part (&quot; &lt;&lt; chunkSize &lt;&lt; &quot; Bytes)... &quot; &lt;&lt; std::endl;
                    recvSize = 0; // Vor jeder Schleife wieder auf 0 setzen
                    while(recvSize &lt; chunkSize)
                    {
                        int bytesToRecv = chunkSize - recvSize;
                        if((bytesRecv = recv(Socket, buf, bytesToRecv &gt; sizeof(buf) ? sizeof(buf) : bytesToRecv, 0)) &lt;= 0)
                        {
							std::cout &lt;&lt; &quot;Error while resiving via chunked&quot; &lt;&lt; std::endl;
							return false;
                        }
                        recvSize += bytesRecv;
                        tmpBody += buf;
                        std::cout &lt;&lt; &quot;\r&quot; &lt;&lt; recvSize * 100 / chunkSize &lt;&lt; &quot;%&quot; &lt;&lt; std::flush;
                    }
                    std::cout &lt;&lt; std::endl;
                    for(int i = 0; i &lt; 2; ++i)
                    {
                        char temp;
                        recv(Socket, &amp;temp, 1, 0);
                    }
                }
            }
        }
        std::cout &lt;&lt; std::endl &lt;&lt; &quot;Finished!&quot; &lt;&lt; std::endl;
		//std::cout &lt;&lt; tmpBody &lt;&lt; std::endl;
		body = tmpBody;
		removeHttp(oldUrl);
		referer = &quot;http://&quot; + oldUrl;
    }
    catch(std::exception&amp; e)
    {
        std::cout &lt;&lt; std::endl;
        std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
    }
	closesocket(Socket);
	return true;
}
</code></pre>
<p>mfg Darter</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/287736/recv-http-problem</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 07:46:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/287736.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 03 Jun 2011 03:51:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to recv HTTP problem on Fri, 03 Jun 2011 04:36:35 GMT]]></title><description><![CDATA[<p>Hey. ein bessere Titel ist mir leider nicht eingefallen xD.</p>
<p>Naja, auf jeden fall hab ich mir ne kleine Klasse aufgebaut, ich poste mal nur die relevante Funktion, da ich keinen Spoiler finden kann xD.</p>
<p>Leider kann ich die Seite, dich ich als Vorlage genommen habe nicht mehr finden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":-("
      alt="😞"
    /></p>
<p>Erstaml etwas erklärt. Ich empfange erst den HTTP header. Anhand des headers wird dann ausgelesen, wie der reste empfangen wird, per content-size, chunked, oder per no given size.</p>
<p>Wird der rest per chunked empfangen, habe im empfangenen quelltext immer mal wider Zeichen wie diese:</p>
<pre><code>ÌÌÌÌÌÌÌÌ
</code></pre>
<p>Ich kann mir nicht erklären, wo diese her kommen.<br />
Die einzige plausieble erklärung für mich wäre, dass das der Hex code ist, welcher ja die größe des zu empfangenen parts darstellt.</p>
<p>Nun die Frage, wie bekomme die diese raus ?</p>
<p>hier mein Code :</p>
<pre><code class="language-cpp">bool WebTCP::navigate(std::string url, std::string post) 
{
	std::string oldUrl = url;
	removeHttp(url);
	std::string hostname = RemoveHostname(url);
	hostent* phe = gethostbyname(hostname.c_str());

	if(phe == NULL)
	{
		std::cout &lt;&lt; &quot;Host konnte nicht aufgelöst werden&quot; &lt;&lt; std::endl;
		return false;
	}

	if(phe-&gt;h_addrtype != AF_INET)
	{
		std::cout &lt;&lt; &quot;Ungueltiger Adresstyp!&quot; &lt;&lt; std::endl;
		return false;
	}

    if(phe-&gt;h_length != 4)
    {
        std::cout &lt;&lt; &quot;Ungueltiger IP-Typ!&quot; &lt;&lt; std::endl;
		return false;
    }

	int Socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

    if(Socket == -1)
    {
        std::cout &lt;&lt; &quot;Socket konnte nicht erstellt werden!&quot; &lt;&lt; std::endl;
		return false;
    }

    sockaddr_in service;
    service.sin_family = AF_INET;
    service.sin_port = htons(80); // Das HTTP-Protokoll benutzt Port 80

    char** p = phe-&gt;h_addr_list; // p mit erstem Listenelement initialisieren
    int result; // Ergebnis von connect
    do
    {
        if(*p == NULL) // Ende der Liste
        {
            std::cout &lt;&lt; &quot;Verbindung fehlgschlagen!&quot; &lt;&lt; std::endl;
			return false;
        }

        service.sin_addr.s_addr = *reinterpret_cast&lt;unsigned long*&gt;(*p);
        ++p;
        result = connect(Socket, reinterpret_cast&lt;sockaddr*&gt;(&amp;service), sizeof(service));
    }
    while(result == -1);

    std::cout &lt;&lt; &quot;Verbindung erfolgreich!&quot; &lt;&lt; std::endl;

	std::string packet;

	if(post.length() &lt; 1)
	{
		packet = &quot;GET &quot; + url + &quot; HTTP/1.1\n&quot;;
		packet += &quot;Host: &quot; + hostname + &quot;\n&quot;;
		packet += &quot;User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.4) Gecko/20100611 AskTbUT2V5/3.8.0.12304 Firefox/3.6.4\n&quot;;
		packet += &quot;Accept: text/javascript, text/html, application/xml, text/xml, */*\n&quot;;
		packet += &quot;Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n&quot;;
		if(referer.length() &gt; 1)
			packet += &quot;Referer: &quot; + referer + &quot;\n&quot;;
		packet += &quot;Keep-Alive: 115\n&quot;;
		packet += &quot;Connection: keep-alive\n\n&quot;;
	}else{

		std::ostringstream Str;
		Str &lt;&lt; post.length();
		std::string postSize(Str.str());	

		packet = &quot;POST &quot; + url + &quot; HTTP/1.1\n&quot;;
		packet += &quot;Host: &quot; + hostname + &quot;\n&quot;;
		packet += &quot;User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.4) Gecko/20100611 AskTbUT2V5/3.8.0.12304 Firefox/3.6.4\n&quot;;
		packet += &quot;Accept: text/javascript, text/html, application/xml, text/xml, */*\n&quot;;
		packet += &quot;Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n&quot;;
		if(referer.length() &gt; 1)
			packet += &quot;Referer: &quot; + referer + &quot;\n&quot;;
		packet += &quot;Keep-Alive: 115\n&quot;;
		packet += &quot;Connection: keep-alive\n&quot;;
		packet += &quot;Content-Type: application/x-www-form-urlencoded\n&quot;;
		packet += &quot;Content-Length: &quot; + postSize;
		packet += &quot;\n\n&quot; + post;
	}
	std::fstream fout(&quot;header&quot;, std::ios::binary | std::ios::out);
    if(!fout)
    {
        std::cout &lt;&lt; &quot;Could Not Create File!&quot; &lt;&lt; std::endl;		
        return false;
    }	
	fout.write(packet.c_str(), packet.length());

	std::cout &lt;&lt; packet &lt;&lt; std::endl; 
	header.clear();

	try
    {		
        SendAll(Socket, packet.c_str(), packet.size());

        int code = 100; // 100 = Continue       
		std::string line;
		std::string msg;
		// HTTP/1.1 200 OK
		boost::regex PatternFirstline(&quot;[^\w]+ ([0-9]+) ([^\n]+)&quot;);		
		boost::cmatch match;	

		std::cout &lt;&lt; &quot;recv header&quot; &lt;&lt; std::endl;

        while(code == 100)
        {
            GetLine(Socket, line);			
			if(boost::regex_match(line.c_str(), match, PatternFirstline))
			{
				code = atof(match[1].str().c_str());
				msg = match[2];
			}else{
				if(line.length() &gt; 1)
				{
					std::cout &lt;&lt; &quot;unerwarteter Fehler!&quot; &lt;&lt; std::endl;
					return false;
				}
			}
            if(code == 100)
            {
                GetLine(Socket, line); // Leere Zeile nach Continue ignorieren				
            }
        }
        std::cout &lt;&lt; &quot;Msg: &quot; &lt;&lt; msg &lt;&lt; std::endl;

        if(code == 500)
        {
            std::cout &lt;&lt; &quot;Error #&quot; &lt;&lt; code &lt;&lt; &quot; - &quot; &lt;&lt; msg &lt;&lt; std::endl;			
            return false;
        }

        bool chunked = false;
        const int noSizeGiven = -1;
        int size = noSizeGiven;

		boost::regex PatternLine(&quot;([^:]+): ([^\n]+)&quot;);	

        while(true)
        {
            GetLine(Socket, line);			
			if(line.find(&quot;\r&quot;) != std::string::npos &amp;&amp; line.length() &lt; 2) // Header zu Ende?
            {
                break;
            }
			if(line.length() &gt; 1)
			{
				if(boost::regex_match(line.c_str(), match, PatternLine))
				{
					if(match[1].str().find(&quot;Content-Length&quot;) != std::string::npos)
					{
						size = atof(match[2].str().c_str());
					}
					else if(match[1].str().find(&quot;Transfer-Encoding&quot;) != std::string::npos)
					{
						if(match[2].str().find(&quot;chunked&quot;) != std::string::npos)
							chunked = true;
					}
					else if (match[1].str().find(&quot;Location&quot;) != std::string::npos)
					{
						if(match[2].str().c_str()[0] == '/')
							hostname += match[2];
						else
							hostname = match[2];
						location = hostname;
						std::cout &lt;&lt; &quot;Location found: &quot; &lt;&lt; hostname &lt;&lt; std::endl;
						if (autoLocation)
						{
							navigate(hostname);
							closesocket(Socket);
							return true;
						}
					}
				}
				else
				{
					std::cout &lt;&lt; &quot;unerwarteter Fehler!&quot; &lt;&lt; std::endl;
					return false;
				}
			}
        }
		// if we come to here no location was found !
		//location.clear();

        int recvSize = 0; // Empfangene Bytes insgesamt
        char buf[1024];
        int bytesRecv = -1; // Empfangene Bytes des letzten recv

		body.clear();
		std::string tmpBody;

        if(size != noSizeGiven) // Wenn die Größe über Content-length gegeben wurde
        {
            std::cout &lt;&lt; &quot;0%&quot;;
            while(recvSize &lt; size)
            {
                if((bytesRecv = recv(Socket, buf, sizeof(buf), 0)) &lt;= 0)
                {
                    std::cout &lt;&lt; &quot;Error while resiving via content-length&quot; &lt;&lt; std::endl;
					return false;
                }
                recvSize += bytesRecv;
				tmpBody += buf;
                std::cout &lt;&lt; &quot;\r&quot; &lt;&lt; recvSize * 100 / size &lt;&lt; &quot;%&quot; &lt;&lt; std::flush; // Mit \r springen wir an den Anfang der Zeile
            }
        }
        else
        {
            if(!chunked)
            {
                std::cout &lt;&lt; &quot;Downloading... (Unknown Filesize)&quot; &lt;&lt; std::endl;
                while(bytesRecv != 0) // Wenn recv 0 zurück gibt, wurde die Verbindung beendet
                {
                    if((bytesRecv = recv(Socket, buf, sizeof(buf), 0)) &lt; 0)
                    {
                    std::cout &lt;&lt; &quot;Error while resiving via unknow size&quot; &lt;&lt; std::endl;
					return false;
                    }
                    tmpBody += buf;
                }
            }
            else
            {
                std::cout &lt;&lt; &quot;Downloading... (Chunked)&quot; &lt;&lt; std::endl;
                while(true)
                {
                    std::stringstream sstream;
                    GetLine(Socket, sstream);
                    int chunkSize = -1;
                    sstream &gt;&gt; std::hex &gt;&gt; chunkSize; // Größe des nächsten Parts einlesen					
                    if(chunkSize &lt;= 0) // Wenn 0 komplett !
                    {
                        break;
                    }
                    std::cout &lt;&lt; &quot;Downloading Part (&quot; &lt;&lt; chunkSize &lt;&lt; &quot; Bytes)... &quot; &lt;&lt; std::endl;
                    recvSize = 0; // Vor jeder Schleife wieder auf 0 setzen
                    while(recvSize &lt; chunkSize)
                    {
                        int bytesToRecv = chunkSize - recvSize;
                        if((bytesRecv = recv(Socket, buf, bytesToRecv &gt; sizeof(buf) ? sizeof(buf) : bytesToRecv, 0)) &lt;= 0)
                        {
							std::cout &lt;&lt; &quot;Error while resiving via chunked&quot; &lt;&lt; std::endl;
							return false;
                        }
                        recvSize += bytesRecv;
                        tmpBody += buf;
                        std::cout &lt;&lt; &quot;\r&quot; &lt;&lt; recvSize * 100 / chunkSize &lt;&lt; &quot;%&quot; &lt;&lt; std::flush;
                    }
                    std::cout &lt;&lt; std::endl;
                    for(int i = 0; i &lt; 2; ++i)
                    {
                        char temp;
                        recv(Socket, &amp;temp, 1, 0);
                    }
                }
            }
        }
        std::cout &lt;&lt; std::endl &lt;&lt; &quot;Finished!&quot; &lt;&lt; std::endl;
		//std::cout &lt;&lt; tmpBody &lt;&lt; std::endl;
		body = tmpBody;
		removeHttp(oldUrl);
		referer = &quot;http://&quot; + oldUrl;
    }
    catch(std::exception&amp; e)
    {
        std::cout &lt;&lt; std::endl;
        std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
    }
	closesocket(Socket);
	return true;
}
</code></pre>
<p>mfg Darter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072621</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072621</guid><dc:creator><![CDATA[Darter]]></dc:creator><pubDate>Fri, 03 Jun 2011 04:36:35 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Fri, 03 Jun 2011 06:56:54 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/27a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--right_arrow"
      title=":arrow_right:"
      alt="➡"
    /> Debugger</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072644</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Fri, 03 Jun 2011 06:56:54 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Fri, 03 Jun 2011 09:56:11 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/27a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--right_arrow"
      title=":arrow_right:"
      alt="➡"
    /> Debugger</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>Ich les mir das jetzt nicht alles haarklein durch, aber ein typischer Fehler wäre eine vergessene Nullterminierung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072717</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Fri, 03 Jun 2011 09:56:11 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Fri, 03 Jun 2011 10:02:15 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>aber ein typischer Fehler wäre eine vergessene Nullterminierung.</p>
</blockquote>
<p>Oder aber nicht beachtet, dass recv und Konsorten eben keine Nullterminierung einbauen sondern zurückgeben, wie viele Zeichen epfangen wurden. Wenn man dann mehr als das einliest, gibts am Ende Zeichensalat frisch aus dem uninitialisierten Buffer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072720</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072720</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Fri, 03 Jun 2011 10:02:15 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Fri, 03 Jun 2011 11:38:48 GMT]]></title><description><![CDATA[<p>Darter schrieb:</p>
<blockquote>
<pre><code class="language-cpp">if(phe-&gt;h_length != 4)
{
	std::cout &lt;&lt; &quot;Ungueltiger IP-Typ!&quot; &lt;&lt; std::endl;
    return false;
}
</code></pre>
</blockquote>
<p>Ich vermute du tust das, weil du kein IPv6 unterstützt. Das ist jedoch nicht nötig, da es für IPv4 (das von dir abgefragte) AF_INET und für IPv6 AF_INET6 gibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072749</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072749</guid><dc:creator><![CDATA[FrEEzE2046]]></dc:creator><pubDate>Fri, 03 Jun 2011 11:38:48 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Fri, 03 Jun 2011 13:17:22 GMT]]></title><description><![CDATA[<p>Eine gängige Technik wäre</p>
<pre><code class="language-cpp">int recvSize = 0; // Empfangene Bytes insgesamt
        char buf[1024];
        int bytesRecv = -1; // Empfangene Bytes des letzten recv

        body.clear();
        std::string tmpBody;

        if(size != noSizeGiven) // Wenn die Größe über Content-length gegeben wurde
        {
            std::cout &lt;&lt; &quot;0%&quot;;
            while(recvSize &lt; size)
            {
                if((bytesRecv = recv(Socket, buf, sizeof(buf)-1, 0)) &lt;= 0)
                // das letzte Byte in buf gehört der \0
                {
                    std::cout &lt;&lt; &quot;Error while resiving via content-length&quot; &lt;&lt; std::endl;
                    return false;
                }
                recvSize += bytesRecv;
                buf[bytesRecv] = \0;
                // die string::operator+(char*) Methode liest bis zum \0 Byte
                tmpBody += buf;
                std::cout &lt;&lt; &quot;\r&quot; &lt;&lt; recvSize * 100 / size &lt;&lt; &quot;%&quot; &lt;&lt; std::flush; // Mit \r springen wir an den Anfang der Zeile
            }
        }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2072795</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072795</guid><dc:creator><![CDATA[muggabatscher]]></dc:creator><pubDate>Fri, 03 Jun 2011 13:17:22 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Fri, 03 Jun 2011 14:48:42 GMT]]></title><description><![CDATA[<p>Hey.</p>
<p>Der letzte beitrag klinkt für mich einleuchten.<br />
allerdings wird das so nicht funktionieren:</p>
<pre><code class="language-cpp">buf[bytesRecv] = \0;
</code></pre>
<p>eher so:</p>
<pre><code class="language-cpp">buf[bytesRecv] = '\0';
</code></pre>
<p>So habe ich es dann auch Probiert, alerdings erhalte ich dann folgenen runtime-Error:</p>
<pre><code>Run-Time Check Failure #2 - Stack around the variable 'buf' was corrupted.
</code></pre>
<p>Also dachte ich mir, ich überlaufe den Index des Arrays und hab es so Probiert:<br />
EDIT: meinte natürlich so:</p>
<pre><code class="language-cpp">buf[bytesRecv - 1] = '\0';
</code></pre>
<p>So wird mir aber leider bei jedem Part das letzte Zeichen &quot;geklaut&quot;.</p>
<p>Außerdem ensteht dieser runtime-Error immer erst dann, wenn der ganze Quelltext schon empfangen wurde.</p>
<p>EDIT: Nun hab ich überprüft wie viele bytes bei jedem druchlauf der Schleife tatsächlich empfangen werden. Bis zum letzen Schleifendurchgang werden immer 1024 Bytes empfangen, also sie größe meines Buffers. Beim letzten durchgang sind es natürlich weniger, da es schon ein extremer Zufall wäre, dass es genau aufgeht, und genau da ensteht der Fehler, was ich mir noch nicht ganz erklären kann</p>
<p>mfg Darter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072832</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072832</guid><dc:creator><![CDATA[Darter]]></dc:creator><pubDate>Fri, 03 Jun 2011 14:48:42 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Fri, 03 Jun 2011 15:09:24 GMT]]></title><description><![CDATA[<p>Du mußt auch daran denken, daß der Buffer groß genug ist für die pro Durchlauf empfangenen Daten UND den Null-Terminator. Darum steht in mugga's Beitrag auch &quot;sizeof(buf)-1&quot; beim recv()-Befehl.</p>
<p>(der Fehler entsteht schon viel früher, wird allerdings erst am Funktionsende bemerkt, wenn die Debug-Sicherungen überprüfen, ob du nichts kaputt gemacht hast)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072854</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072854</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 03 Jun 2011 15:09:24 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Fri, 03 Jun 2011 16:43:27 GMT]]></title><description><![CDATA[<p>Sorry, hätte das wohl deutlicher kennzeichnen müssen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072909</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072909</guid><dc:creator><![CDATA[muggabatscher]]></dc:creator><pubDate>Fri, 03 Jun 2011 16:43:27 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Fri, 03 Jun 2011 16:57:22 GMT]]></title><description><![CDATA[<p>Ok, sry hab ich doch tatsächlich übersehen, also lag ich doch richtig, dass ich den Index des Array überlaufe. (so nebenbei, sagt man dass so ? ^^)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072913</guid><dc:creator><![CDATA[Darter]]></dc:creator><pubDate>Fri, 03 Jun 2011 16:57:22 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Sat, 04 Jun 2011 06:50:07 GMT]]></title><description><![CDATA[<p>Im englischen sagt man &quot;Index out of range&quot; - wie man das ordentlich ins Deutsche übersetzen soll, keine Ahnung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2073119</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2073119</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Sat, 04 Jun 2011 06:50:07 GMT</pubDate></item><item><title><![CDATA[Reply to recv HTTP problem on Sat, 04 Jun 2011 07:26:15 GMT]]></title><description><![CDATA[<p>Darter schrieb:</p>
<blockquote>
<p>dass ich den Index des Array überlaufe. (so nebenbei, sagt man dass so ? ^^)</p>
</blockquote>
<p>Das Array hat keinen Index, also kannst du ihn auch nicht überlaufen. Du greifst mit dem Index auf das Array zu. Und in diesem Fall überschreitest du den bereich des Arrays.</p>
<p>theliquidwave schrieb:</p>
<blockquote>
<p>Im englischen sagt man &quot;Index out of range&quot;</p>
</blockquote>
<p>Ich meine, was von &quot;Bereichsüberlauf&quot; oder &quot;Bereichsüberschreitung&quot; im Hinterkopf zu haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2073125</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2073125</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Sat, 04 Jun 2011 07:26:15 GMT</pubDate></item></channel></rss>