Hi all,
I have developed an C++ application with Visual Studio 2005 and in them i want save some files in a remote server using IXMLHTTPRequest component. usually before save the file, i read the directory tree in remote server and user can select the right destination directory and often everything is OK and the application works fine.Except unfortunately when the destination directory(or actually the full path) is too long, the "send" method does not return and readyState remain 2, but on other hand file is correctly saved in remote server.
In this way i have tried to use a network monitoring pplication(Ethereal) and i observed that a "PUT" request is sent to remote server and then "200" response is received form the server and according to this observation the file was saved correctly. I think that i have problem with my client(MSXML4.DLL) or any internet setting.
Everybody can give me any recommendations to resolve this problem.
Thanks in advance
Alireza
1 7297
Hi,
After some days nobody has answered me. I write a piece of code that I'm using
it, that probably may be helpful. Or it's possible, that i have a misunderstanding to
selecting the C/C++ forum? Please hint me if it's true.
Here is the code: - void CWebDAVOperation::GetWebDAVDirTree()
-
{
-
// Variables.
-
HRESULT hr;
-
IXMLHTTPRequestPtr pRequest = NULL;
-
-
long lStatus = 0;
-
BSTR bstrResp;
-
BSTR bstrResponseText;
-
CString strQuery;
-
CString strDir = skillInfo.m_strAgentDirURI + _T("/") + m_strCallLogDir;
-
-
// Create an instance of the request object.
-
hr=pRequest.CreateInstance("Msxml2.XMLHTTP.4.0");
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
try
-
{
-
// Open the XMLHTTPRequest object with the SEARCH method and
-
// specify that it will be sent asynchronously.
-
hr=pRequest->open("SEARCH", _bstr_t(strDir), false, _bstr_t(skillInfo.m_strAgentUserName) , _bstr_t(skillInfo.m_strAgentPassword));
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
// Set the Content-Type header.
-
hr=pRequest->setRequestHeader((bstr_t)"Content-Type", (bstr_t)"text/xml");
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
// Build the query for a hierarchical search.
-
strQuery = _T("<?xml version=\"1.0\"?><D:searchrequest xmlns:D = \"DAV:\" >");
-
strQuery += _T("<D:sql>SELECT \"DAV:href\" FROM scope('deep traversal of \"");
-
strQuery += strDir;
-
strQuery += _T("\"')");
-
strQuery += _T("WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\" = True");
-
strQuery += _T("</D:sql></D:searchrequest>");
-
-
// Send the SEARCH method request.
-
hr=pRequest->send(_bstr_t(strQuery));
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
// Get the response status.
-
pRequest->get_status(&lStatus);
-
-
// An error occurred on the server.
-
if(lStatus >= 500)
-
{
-
// report the error...
-
}
-
-
// The method request was successful.
-
else if (lStatus == 207)
-
{
-
// Variables.
-
MSXML2::IXMLDOMDocumentPtr pDOMDoc = NULL;
-
MSXML2::IXMLDOMNodeListPtr pDOMNodeList = NULL;
-
MSXML2::IXMLDOMNodePtr pDOMNode = NULL;
-
BSTR bstrRespText;
-
-
// Create an instance of the DOM Document.
-
HRESULT hr = pDOMDoc.CreateInstance(__uuidof(MSXML2::DOMDocument));
-
-
// Check the status of pointer creation.
-
if(FAILED(hr))
-
{
-
// report the error...
-
}
-
-
// Get the method response XML text.
-
pRequest->get_responseText(&bstrRespText);
-
-
// Load the XML document with the response text.
-
pDOMDoc->loadXML(bstrRespText);
-
-
// Build a list of the DAV:href XML nodes, corresponding to the folders
-
// returned in the search request. The DAV: namespace is typically
-
// assigned the a: prefix in the XML response body.
-
pDOMNodeList = pDOMDoc->getElementsByTagName((bstr_t)"a:prop");
-
//pDOMNodeList = pDOMDoc->getElementsByTagName((bstr_t)"a:href");
-
-
// Display the number of folders found.
-
long lLen, lShowLen;
-
pDOMNodeList->get_length(&lLen);
-
-
::SysFreeString(bstrRespText);
-
-
lShowLen = lLen;
-
// List the folders found.
-
for(int i=0; i<lLen;i++)
-
{
-
pDOMNode = pDOMNodeList->nextNode();
-
if(pDOMNode != NULL)
-
{
-
BSTR bstrText;
-
pDOMNode->get_text(&bstrText);
-
CString strText(bstrText);
-
-
// i save the folder name
-
// ...
-
-
::SysFreeString(bstrText);
-
}
-
}
-
}
-
else
-
{
-
// report the lStatus
-
}
-
-
pRequest = NULL;
-
}
-
catch(_com_error& e)
-
{
-
-
// report the error message
-
-
pRequest = NULL;
-
-
}
-
}
-
-
bool CWebDAVOperation::SaveStream(IStream* pIStream, CString strPath, CString strUserName, CString strPassword)
-
{
-
HRESULT hr;
-
int WebDavStep = 0;
-
BSTR bstrString = NULL;
-
IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
-
try
-
{
-
WebDavStep ++;
-
hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.4.0");
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
bstrString = _bstr_t(strPath);
-
-
WebDavStep ++;
-
hr=pIXMLHTTPRequest->open("PUT", bstrString, false, _bstr_t(strUserName) , _bstr_t(strPassword));
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
WebDavStep ++;
-
// Set the Content-Type header.
-
hr=pIXMLHTTPRequest ->setRequestHeader((bstr_t)"Content-Type", (bstr_t)"audio/mpeg3");
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
WebDavStep ++;
-
// Set the Translate header to False.
-
hr=pIXMLHTTPRequest ->setRequestHeader((bstr_t)"Translate", (bstr_t)"f");
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
WebDavStep ++;
-
hr=pIXMLHTTPRequest->send(pIStream);
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
BSTR bstrValue = NULL;
-
WebDavStep ++;
-
hr=pIXMLHTTPRequest->get_responseText(&bstrValue);
-
CString Str1, Str2;
-
CString strResp(bstrValue);
-
-
// report resonseText
-
//...
-
-
::SysFreeString(bstrValue);
-
bstrValue = NULL;
-
-
pIXMLHTTPRequest = NULL;
-
-
if(bstrString)
-
{
-
::SysFreeString(bstrString);
-
bstrString = NULL;
-
}
-
-
return true;
-
}
-
catch(_com_error& e)
-
{
-
-
// report the error message
-
-
pIXMLHTTPRequest = NULL;
-
-
}
-
-
return false;
-
}
-
and after some checks I've tried to use asynchronous mode with following code: - bool CWebDAVOperation::SaveStream(IStream* pIStream, CString strPath, CString strUserName, CString strPassword)
-
{
-
HANDLE completedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
-
-
// ...
-
-
WebDavStep ++;
-
hr=pIXMLHTTPRequest->open("PUT", bstrString, true, _bstr_t(strUserName) , _bstr_t(strPassword));
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
// ...
-
-
// Hook up the onreadystatechange event handler
-
IDispatch *sink = new XMLHttpEventSink(pIXMLHTTPRequest, completedEvent, &m_lstate);
-
hr=pIXMLHTTPRequest->put_onreadystatechange(sink);
-
-
WebDavStep ++;
-
hr=pIXMLHTTPRequest->send(pIStream);
-
SUCCEEDED(hr) ? 0 : throw hr;
-
-
// Since this is a console app the process would end if we just continued from here.
-
// So we wait until the async request is done (in real life, this means we didn't
-
// need an async request in the first place, but this is a sample, not real life).
-
-
do
-
{
-
DWORD dwRetp = WaitForSingleObject(completedEvent, 1000);
-
-
// report the m_lState (readyState)
-
-
if(dwRetp == WAIT_OBJECT_0)
-
break;
-
}while(true);
-
-
sink->Release();
-
-
CloseHandle(completedEvent);
-
-
// ...
-
}
-
-
-
STDMETHODIMP XMLHttpEventSink::Invoke(DISPID dispIdMember, const IID &riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
-
{
-
// Since this class isn't used for anything else, Invoke will get called only for onreadystatechange, and
-
// dispIdMember will always be 0.
-
-
long state;
-
// Retrieve the state
-
_request->get_readyState(&state);
-
*m_plState = state;
-
//std::wcout << L"State: " << state << std::endl;
-
-
if( state == 4 )
-
{
-
// The request has completed.
-
// Get the request status.
-
-
//long status;
-
//_request->get_status(&status);
-
-
// std::wcout << L"Status: " << status << std::endl;
-
-
// Signal the main thread we're done.
-
SetEvent(_completedEvent);
-
}
-
return S_OK;
-
}
I will be thankful if anyone can help me.
Thanks in advance.
Alireza
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bura Tino |
last post by:
Hi,
I took a sample below almost verbatim from the MS MSXML 3.0 website and the
line
hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP");
never succeeds. What am I doing wrong?
It says...
|
by: JXP |
last post by:
Hello,
I am attempting to send url with '\n' in some place.
the url is like this:
"http://localhost/MyFile.xml?param1=hello\nbye\n"
I put this url in CString class and I run this code:
|
by: Agam Mehta |
last post by:
Hi,
Everything works fine with ixmlhttprequest. It gives me "access
violation" only when i am trying to release it from the memory (i.e
pXMLHttpReq->Release()).
Below is my code....
|
by: Joseph |
last post by:
I have been using "XMLHTTPClass" in an asp.net module. It is properly
referenced and was working up until recently. Now it is failing with the
error message "QueryInterface for interface...
|
by: Greg |
last post by:
Hi,
I've designed a bookmark in Ajax / PHP that I will put soon on
sourceforge.net.
But I've got an very tricky bug.
I try it on some computers with Internet Explorer/Windows, Firefox...
|
by: Eric Wallstedt |
last post by:
I have a page that "logs" changes made to input fields using ajax to
pass data to a cgi. I use POST and it works fine most of the time (all
the time in IE). But it fails when I get the data from...
|
by: hug |
last post by:
www.webmaster, was suggested that this ng
could be a better place.]
I've updated my test server to handle if-modified-since. I've noticed
that the (old copies I run of) IE and Netscape seem...
|
by: bhushanbsc |
last post by:
Hi,
I am working on a project related to windows pocket pc 5.0 (win32).
in that i am trying client-server communicationusing SOAP server.
but facing problem on...
|
by: AlirezaShokoienia |
last post by:
Hi all,
I'm new in "bytes" and don't know that my question is related to this forum? Anyway...
I wrote an application and have used form this component to "PUT" files in a remote server and in this...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |