<?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[HTTP Anfrage -&amp;gt; es tritt immer eine Exception auf]]></title><description><![CDATA[<p>Sorry, aber schon wieder nen Thread von mir <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
<p>Ich Frage in einem Dialog, den Server und die URI ab, dann führe ich in einem<br />
Thread folgenden Code aus:</p>
<pre><code class="language-cpp">UINT InternetSteuerungsfkt (LPVOID pParam)
{
	CCommunication *ThreadCom = static_cast&lt; CCommunication * &gt;(pParam);
	const UINT PUFFRGR = 1000;
	CInternetSession InetSession;
	CHttpConnection *pHttpCon = NULL;
	CHttpFile *pHttpFile = NULL;
	INTERNET_PORT Port = 80;
	char *puffer = new char[PUFFRGR];

	for (register int i = 0; i &lt; ThreadCom-&gt;getCount (); i++)
	{
		try {

			pHttpCon = InetSession.GetHttpConnection (ThreadCom-&gt;getServer (), Port);
			pHttpFile = pHttpCon-&gt;OpenRequest (CHttpConnection::HTTP_VERB_GET, ThreadCom-&gt;getUri ());
			pHttpFile-&gt;SendRequest ();
			int BytesGelesen = pHttpFile-&gt;Read (puffer, PUFFRGR-1);
			puffer[BytesGelesen] = '\0';
			PostMessage (ThreadCom-&gt;getHwnd (), WM_STATUS, i, 0);
			Sleep (ThreadCom-&gt;getPause () * 1000);

		}
		catch (CInternetException *e) {
			e-&gt;Delete ();		
		}
	}

	delete[] puffer;
	delete pHttpFile;
	delete pHttpCon;

	return 0;
}
</code></pre>
<p>Die Klasse CCommunication dient der Kommunikation zwischen dem Thread und dem<br />
Hauptthread:</p>
<pre><code class="language-cpp">class CCommunication
{
public:
	CCommunication(CString &amp;u, CString &amp;s, int &amp;p, int &amp;c, HWND h);
	~CCommunication(void);
	const CString &amp; getUri (void) const;
	const CString &amp; getServer (void) const;
	const int &amp; getPause (void) const;
	const int &amp; getCount (void) const;
	const HWND  getHwnd (void) const;
private:
	CString m_server;
	CString m_uri;
	int m_pause;
	int m_count;
	HWND m_hWnd;
};
</code></pre>
<p>Der Thread wird so gestartet:</p>
<pre><code class="language-cpp">void CChildView::OnDateiGet()
{
	CGDlg dlg;
	dlg.DoModal ();
	int count = atoi (dlg.m_count);
	int pause = atoi (dlg.m_pause); 

	CCommunication *ThreadCom = new CCommunication(dlg.m_server, dlg.m_uri, pause, count, GetSafeHwnd ());

	CWinThread *pThread = AfxBeginThread (InternetSteuerungsfkt, ThreadCom);

}
</code></pre>
<p>Ich verstehe nicht weshalb ich eine Exception bekomme, wenn ich als Server<br />
localhost und als URI / angebe. Gebe ich das direkt im Code ein, funktioniert<br />
es doch auch. Könnt ihr mir hier vllt. sagen weshalb?<br />
Und wie kann ich den Errortyp bei einer CInternetException abfragen? In der Doku<br />
stand dazu nichts konkretes.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/69769/http-anfrage-gt-es-tritt-immer-eine-exception-auf</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 19:15:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/69769.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 31 Mar 2004 13:01:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to HTTP Anfrage -&amp;gt; es tritt immer eine Exception auf on Wed, 31 Mar 2004 13:01:24 GMT]]></title><description><![CDATA[<p>Sorry, aber schon wieder nen Thread von mir <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
<p>Ich Frage in einem Dialog, den Server und die URI ab, dann führe ich in einem<br />
Thread folgenden Code aus:</p>
<pre><code class="language-cpp">UINT InternetSteuerungsfkt (LPVOID pParam)
{
	CCommunication *ThreadCom = static_cast&lt; CCommunication * &gt;(pParam);
	const UINT PUFFRGR = 1000;
	CInternetSession InetSession;
	CHttpConnection *pHttpCon = NULL;
	CHttpFile *pHttpFile = NULL;
	INTERNET_PORT Port = 80;
	char *puffer = new char[PUFFRGR];

	for (register int i = 0; i &lt; ThreadCom-&gt;getCount (); i++)
	{
		try {

			pHttpCon = InetSession.GetHttpConnection (ThreadCom-&gt;getServer (), Port);
			pHttpFile = pHttpCon-&gt;OpenRequest (CHttpConnection::HTTP_VERB_GET, ThreadCom-&gt;getUri ());
			pHttpFile-&gt;SendRequest ();
			int BytesGelesen = pHttpFile-&gt;Read (puffer, PUFFRGR-1);
			puffer[BytesGelesen] = '\0';
			PostMessage (ThreadCom-&gt;getHwnd (), WM_STATUS, i, 0);
			Sleep (ThreadCom-&gt;getPause () * 1000);

		}
		catch (CInternetException *e) {
			e-&gt;Delete ();		
		}
	}

	delete[] puffer;
	delete pHttpFile;
	delete pHttpCon;

	return 0;
}
</code></pre>
<p>Die Klasse CCommunication dient der Kommunikation zwischen dem Thread und dem<br />
Hauptthread:</p>
<pre><code class="language-cpp">class CCommunication
{
public:
	CCommunication(CString &amp;u, CString &amp;s, int &amp;p, int &amp;c, HWND h);
	~CCommunication(void);
	const CString &amp; getUri (void) const;
	const CString &amp; getServer (void) const;
	const int &amp; getPause (void) const;
	const int &amp; getCount (void) const;
	const HWND  getHwnd (void) const;
private:
	CString m_server;
	CString m_uri;
	int m_pause;
	int m_count;
	HWND m_hWnd;
};
</code></pre>
<p>Der Thread wird so gestartet:</p>
<pre><code class="language-cpp">void CChildView::OnDateiGet()
{
	CGDlg dlg;
	dlg.DoModal ();
	int count = atoi (dlg.m_count);
	int pause = atoi (dlg.m_pause); 

	CCommunication *ThreadCom = new CCommunication(dlg.m_server, dlg.m_uri, pause, count, GetSafeHwnd ());

	CWinThread *pThread = AfxBeginThread (InternetSteuerungsfkt, ThreadCom);

}
</code></pre>
<p>Ich verstehe nicht weshalb ich eine Exception bekomme, wenn ich als Server<br />
localhost und als URI / angebe. Gebe ich das direkt im Code ein, funktioniert<br />
es doch auch. Könnt ihr mir hier vllt. sagen weshalb?<br />
Und wie kann ich den Errortyp bei einer CInternetException abfragen? In der Doku<br />
stand dazu nichts konkretes.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/492428</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/492428</guid><dc:creator><![CDATA[SirLant]]></dc:creator><pubDate>Wed, 31 Mar 2004 13:01:24 GMT</pubDate></item><item><title><![CDATA[Reply to HTTP Anfrage -&amp;gt; es tritt immer eine Exception auf on Thu, 01 Apr 2004 07:54:15 GMT]]></title><description><![CDATA[<p>SirLant schrieb:</p>
<blockquote>
<p>Gebe ich das direkt im Code ein, funktioniert<br />
es doch auch.</p>
</blockquote>
<p>Hast Du mal geprüft ob die Variablen auch wirklich den richtigen Wert enthalten ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/492803</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/492803</guid><dc:creator><![CDATA[Knuddlbaer]]></dc:creator><pubDate>Thu, 01 Apr 2004 07:54:15 GMT</pubDate></item><item><title><![CDATA[Reply to HTTP Anfrage -&amp;gt; es tritt immer eine Exception auf on Thu, 01 Apr 2004 10:52:14 GMT]]></title><description><![CDATA[<p>Als ich mal alle Werte der Reihe nach ausgegeben habe, fiel mir auf, dass ich die<br />
Parameter für den server und uri vertauscht habe, beim Erzeugen des Objektes.<br />
Ich kann mich zwar nicht erinnern, wann ich da rumgespielt habe, aber anscheinend<br />
habe ich es, denn vorher hatte er die Daten immer richtig drin.</p>
<p>Danke, dass du mich dazu aufgefordert hast nochmal alles zu checken, in Zukunft<br />
werde ich immer explizit checken, auch wenn ich denke es würde passen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/492944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/492944</guid><dc:creator><![CDATA[SirLant]]></dc:creator><pubDate>Thu, 01 Apr 2004 10:52:14 GMT</pubDate></item><item><title><![CDATA[Reply to HTTP Anfrage -&amp;gt; es tritt immer eine Exception auf on Thu, 01 Apr 2004 11:02:57 GMT]]></title><description><![CDATA[<p>1Problem habe ich aber immernoch, es funktioniert perfekt für 2Durchläufe im<br />
dritten Durchlauf bleibt er jedoch bei pHttpFile-&gt;SendRequest (); stehen, dann<br />
tut sich nichts mehr.<br />
Die dritte Anfrage kommt auch nie bei meinem Server an, da nichts in der access.log steht,<br />
die ersten zwei stehen wie alle Zugriffe drin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/492950</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/492950</guid><dc:creator><![CDATA[SirLant]]></dc:creator><pubDate>Thu, 01 Apr 2004 11:02:57 GMT</pubDate></item></channel></rss>