Zum Inhalt springen

Empfohlene Beiträge

Geschrieben

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

Geschrieben

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)

Geschrieben

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 Benutzerkonto oder melde Dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde Dich hier an.

Jetzt anmelden

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...