Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo Forum,

ich habe folgendes Problem: Ich möchte eine CSV-Datei per WebDav hochladen. Jetzt gibt es keine direkte Bibliothek für C++ die das macht. Also habe ich die CInternetSession, CHttpConnection und CHttpFile Bibliothek verwendet. Das WebDav-Protokoll ist ja lediglich eine Erweiterung des HTTP-Protokolls (wenn ich das richtig verstanden habe).

Dabei kam folgender Code raus:


	int iLen = 13;

	//const TCHAR szHeaders[] = _T("Translate: f");

	const TCHAR szHeaders[] = _T("User-Agent: Microsoft Data Access Internet Publishing Provider DAV\r\n");

	CString strUrl, strPort;


	this->m_EditUrl.GetWindowText(strUrl);

	this->m_EditPort.GetWindowText(strPort);


	if (!strPort.IsEmpty())

		strUrl.AppendFormat(_T(":%s"), strPort.GetString());


	strUrl.Append(_T("/"));


	CString strFile, strUserName, strPassword;


	this->m_MFCEditFilePath.GetWindowText(strFile);

	this->m_EditUserName.GetWindowText(strUserName);

	this->m_EditPassword.GetWindowText(strPassword);


	BOOL bRetVal = TRUE;


	CInternetSession objSession;

	CHttpConnection* pHttpServer = NULL;

	CHttpFile* pHttpFile = NULL;


	CFile objFile;

	CFileException objFileException;


	if (objFile.Open(strFile.GetString(), CFile::modeRead, &objFileException))

	{

		try

		{

			CString strServer, strObject;

			INTERNET_PORT nPort;

			DWORD dwServiceType;


			if (!AfxParseURL(strUrl + strFile, dwServiceType, strServer, strObject, nPort) || dwServiceType != INTERNET_SERVICE_HTTP)

			{

				ASSERT(FALSE);

				return; // false

			}


			pHttpServer = objSession.GetHttpConnection(strServer, nPort, strUserName, strPassword);

			pHttpFile = pHttpServer->OpenRequest(CHttpConnection::HTTP_VERB_PUT, strFile);


			long lLen = 0, lBuffer = 1024;

			BYTE Buffer[1024];


			while (lLen < (long)objFile.GetLength())

			{

				objFile.Read(Buffer, lBuffer);

				pHttpFile->SendRequest(szHeaders, iLen, (LPVOID)Buffer, lBuffer);


				ZeroMemory(Buffer, lBuffer);

				lLen += lBuffer;

			}


			pHttpFile->EndRequest();


			if (pHttpFile)

				pHttpFile->Close();


			pHttpServer->Close();

		}

		catch (CInternetException* pEx)

		{

			// catch errors from WinINet

			TCHAR szErr[1024];

			pEx->GetErrorMessage(szErr, 1024);

			pEx->Delete();


			AfxMessageBox(szErr);


			bRetVal = FALSE;

		}


		if (pHttpFile != NULL)

			delete pHttpFile;


		if (pHttpServer != NULL)

			delete pHttpServer;


		objSession.Close();

	}

	else

		bRetVal = FALSE;

In der Zeile:

pHttpFile->EndRequest();

bekomme ich ein ASSERT und die Datei wird nicht hochgeladen. Wo liegt mein Fehler? Hat jemand eine Idee?

Beste Grüße

Patrick

  • Autor

Ich bekomme folgenden ASSERT:


Debug Assertion Failed!


Program: C:\Projekte\TTF Development\WebDav\Debug\WebDav.exe

File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\inet.cpp

Line: 2212


For information on how your program can cause an assertion

failure, see the Visual C++ documentation on asserts.


(Press Retry to debug the application)

  • Autor

Hallo Klotzkopp,

danke für Deinen Hinweis. Der Nachteil an Deiner Lösung ist, dass ich immer ein Netzlaufwerk Mappen muss. Dies ist natürlich in einem Programm welches ggf. als Dienst läuft, keine Lösung.

Nach ein wenig (stunden ;-) ) suchen, habe ich folgende Lösung, die Einwandfrei funktioniert, auf der MSDN gefunden:

Creating Items (WebDAV)

Beste Grüße

Patrick

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.