473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

IXMLHTTPRequest problem

Hi all,

I have developed an application and in them i want save some files in a remote
server. 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 application(Ethereal) und 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.
Thanks in advance

Alireza
Sep 14 '08 #1
9 1979
acoder
16,027 Expert Mod 8TB
Can you post the code you're using. It may help debug the problem.
Sep 14 '08 #2
Can you post the code you're using. It may help debug the problem.
Hi acoder, and thank you for your reply.

Here is the code of two functions that I'm using. I've omitted some codes those are not important such as reporting errors to make shorter message :


Expand|Select|Wrap|Line Numbers
  1. void CWebDAVOperation::GetWebDAVDirTree()
  2. {
  3.     // Variables.
  4.     HRESULT hr; 
  5.     IXMLHTTPRequestPtr pRequest = NULL;
  6.  
  7.     long lStatus = 0;
  8.     BSTR bstrResp;
  9.     BSTR bstrResponseText;
  10.     CString strQuery;
  11.     CString strDir = skillInfo.m_strAgentDirURI + _T("/") + m_strCallLogDir;
  12.  
  13.     // Create an instance of the request object.
  14.     hr=pRequest.CreateInstance("Msxml2.XMLHTTP.6.0");
  15.     SUCCEEDED(hr) ? 0 : throw hr;
  16.  
  17.     try
  18.     {
  19.         // Open the XMLHTTPRequest object with the SEARCH method and
  20.         // specify that it will be sent asynchronously.
  21.         hr=pRequest->open("SEARCH", _bstr_t(strDir), false, _bstr_t(skillInfo.m_strAgentUserName) , _bstr_t(skillInfo.m_strAgentPassword));
  22.         SUCCEEDED(hr) ? 0 : throw hr;
  23.  
  24.         // Set the Content-Type header.
  25.         hr=pRequest->setRequestHeader((bstr_t)"Content-Type", (bstr_t)"text/xml");
  26.         SUCCEEDED(hr) ? 0 : throw hr;
  27.  
  28.         // Build the query for a hierarchical search.
  29.         strQuery = _T("<?xml version=\"1.0\"?><D:searchrequest xmlns:D = \"DAV:\" >");
  30.         strQuery += _T("<D:sql>SELECT \"DAV:href\" FROM scope('deep traversal of \"");
  31.         strQuery += strDir;
  32.         strQuery += _T("\"')");
  33.         strQuery += _T("WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\" = True");
  34.         strQuery += _T("</D:sql></D:searchrequest>");
  35.  
  36.         // Send the SEARCH method request.
  37.         hr=pRequest->send(_bstr_t(strQuery));
  38.         SUCCEEDED(hr) ? 0 : throw hr;
  39.  
  40.         // Get the response status.
  41.         pRequest->get_status(&lStatus);
  42.  
  43.         // An error occurred on the server.
  44.         if(lStatus >= 500)
  45.         {
  46.             // report the error...
  47.         }
  48.  
  49.         // The method request was successful.
  50.         else if (lStatus == 207)
  51.         {
  52.             // Variables.
  53.             MSXML2::IXMLDOMDocumentPtr pDOMDoc = NULL;
  54.             MSXML2::IXMLDOMNodeListPtr pDOMNodeList = NULL;
  55.             MSXML2::IXMLDOMNodePtr pDOMNode = NULL;
  56.             BSTR bstrRespText;
  57.  
  58.             // Create an instance of the DOM Document.
  59.             HRESULT hr = pDOMDoc.CreateInstance(__uuidof(MSXML2::DOMDocument));
  60.  
  61.             // Check the status of pointer creation.
  62.             if(FAILED(hr))
  63.             {
  64.                 // report the error...
  65.             }
  66.  
  67.             // Get the method response XML text.
  68.             pRequest->get_responseText(&bstrRespText);
  69.  
  70.             // Load the XML document with the response text.
  71.             pDOMDoc->loadXML(bstrRespText);
  72.  
  73.             // Build a list of the DAV:href XML nodes, corresponding to the folders
  74.             // returned in the search request. The DAV: namespace is typically
  75.             // assigned the a: prefix in the XML response body.
  76.             pDOMNodeList = pDOMDoc->getElementsByTagName((bstr_t)"a:prop");
  77.             //pDOMNodeList = pDOMDoc->getElementsByTagName((bstr_t)"a:href");
  78.  
  79.             // Display the number of folders found.
  80.             long lLen, lShowLen;
  81.             pDOMNodeList->get_length(&lLen);
  82.  
  83.             ::SysFreeString(bstrRespText);
  84.  
  85.             lShowLen = lLen;
  86.             // List the folders found.
  87.             for(int i=0; i<lLen;i++)
  88.             {
  89.                 pDOMNode = pDOMNodeList->nextNode();
  90.                 if(pDOMNode != NULL)
  91.                 {
  92.                     BSTR bstrText;
  93.                     pDOMNode->get_text(&bstrText);
  94.                     CString strText(bstrText);
  95.  
  96.                     // i save the folder name
  97.                     // ...
  98.  
  99.                     ::SysFreeString(bstrText);
  100.                 }
  101.             }
  102.         }
  103.         else
  104.         {
  105.             // report the lStatus
  106.         }
  107.  
  108.         pRequest = NULL;
  109.     }
  110.     catch(_com_error& e)
  111.     {
  112.  
  113.         // report the error message
  114.  
  115.         pRequest = NULL;
  116.  
  117.     }
  118. }
  119.  
  120. bool CWebDAVOperation::SaveStream(IStream* pIStream, CString strPath, CString strUserName, CString strPassword)
  121. {
  122.     HRESULT hr;
  123.     int WebDavStep = 0;
  124.     BSTR bstrString = NULL;
  125.     IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
  126.     try
  127.     {
  128.         WebDavStep ++;
  129.         hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.6.0");
  130.         SUCCEEDED(hr) ? 0 : throw hr;
  131.  
  132.         bstrString =  _bstr_t(strPath);
  133.  
  134.         WebDavStep ++;
  135.         hr=pIXMLHTTPRequest->open("PUT", bstrString, false, _bstr_t(strUserName) , _bstr_t(strPassword));
  136.         SUCCEEDED(hr) ? 0 : throw hr;
  137.  
  138.         WebDavStep ++;
  139.         // Set the Content-Type header.
  140.         hr=pIXMLHTTPRequest ->setRequestHeader((bstr_t)"Content-Type", (bstr_t)"audio/mpeg3");
  141.         SUCCEEDED(hr) ? 0 : throw hr;
  142.  
  143.         WebDavStep ++;
  144.         // Set the Translate header to False.
  145.         hr=pIXMLHTTPRequest ->setRequestHeader((bstr_t)"Translate", (bstr_t)"f");
  146.         SUCCEEDED(hr) ? 0 : throw hr;
  147.  
  148.         WebDavStep ++;
  149.         hr=pIXMLHTTPRequest->send(pIStream);
  150.         SUCCEEDED(hr) ? 0 : throw hr;
  151.  
  152.         BSTR bstrValue = NULL;
  153.         WebDavStep ++;
  154.         hr=pIXMLHTTPRequest->get_responseText(&bstrValue);
  155.         CString Str1, Str2;
  156.         CString strResp(bstrValue);
  157.  
  158.         // report resonseText
  159.         //...
  160.  
  161.         ::SysFreeString(bstrValue);
  162.         bstrValue = NULL;
  163.  
  164.         pIXMLHTTPRequest = NULL;
  165.  
  166.         if(bstrString)
  167.         {
  168.              ::SysFreeString(bstrString);
  169.              bstrString = NULL;
  170.         }
  171.  
  172.         return true;
  173.     }
  174.     catch(_com_error& e)
  175.     {
  176.  
  177.         // report the error message
  178.  
  179.         pIXMLHTTPRequest = NULL;
  180.  
  181.     }
  182.  
  183.     return false;
  184. }
  185.  
thanks a lot.
Alireza
Sep 15 '08 #3
Hi acoder,

I must be tell that the previous code was my first try in synchronous form, but I've tried to send the request in asynchronous mode.
Here is the code:

Expand|Select|Wrap|Line Numbers
  1. bool CWebDAVOperation::SaveStream(IStream* pIStream, CString strPath, CString strUserName, CString strPassword)
  2. {
  3.  
  4. //...
  5.         HANDLE completedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  6.  
  7.         // ...
  8.  
  9.         WebDavStep ++;
  10.         hr=pIXMLHTTPRequest->open("PUT", bstrString, true, _bstr_t(strUserName) , _bstr_t(strPassword));
  11.         SUCCEEDED(hr) ? 0 : throw hr;
  12.  
  13.         // ...
  14.  
  15.         // Hook up the onreadystatechange event handler
  16.         IDispatch *sink = new XMLHttpEventSink(pIXMLHTTPRequest, completedEvent, &m_lstate);
  17.         hr=pIXMLHTTPRequest->put_onreadystatechange(sink);
  18.  
  19.         WebDavStep ++;
  20.         hr=pIXMLHTTPRequest->send(pIStream);
  21.         SUCCEEDED(hr) ? 0 : throw hr;
  22.  
  23.         // Since this is a console app the process would end if we just continued from here.
  24.         // So we wait until the async request is done (in real life, this means we didn't
  25.         // need an async request in the first place, but this is a sample, not real life).
  26.  
  27.         do
  28.         {
  29.             DWORD dwRetp = WaitForSingleObject(completedEvent, 1000);
  30.  
  31.             // report the m_lState (readyState)
  32.  
  33.             if(dwRetp == WAIT_OBJECT_0)
  34.                 break;
  35.         }while(true);
  36.  
  37.         sink->Release();
  38.  
  39.         CloseHandle(completedEvent);
  40.  
  41.         // ...
  42.  
  43. }
  44.  
  45.  
  46. STDMETHODIMP XMLHttpEventSink::Invoke(DISPID dispIdMember, const IID &riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
  47. {
  48.     // Since this class isn't used for anything else, Invoke will get called only for onreadystatechange, and
  49.     // dispIdMember will always be 0.
  50.  
  51.     long state;
  52.     // Retrieve the state
  53.     _request->get_readyState(&state);
  54.     *m_plState = state;
  55.     //std::wcout << L"State: " << state << std::endl;
  56.  
  57.     if( state == 4 )
  58.     {
  59.         // The request has completed.
  60.         // Get the request status.
  61.  
  62.         //long status;
  63.         //_request->get_status(&status);
  64.  
  65.        // std::wcout << L"Status: " << status << std::endl;
  66.  
  67.         // Signal the main thread we're done.
  68.         SetEvent(_completedEvent);
  69.     }
  70.     return S_OK;
  71. }
  72.  
thanks again.
Alireza
Sep 15 '08 #4
acoder
16,027 Expert Mod 8TB
OK, this is not JavaScript. It seems like you're using Web DAV. I have no experience of it, so can't be much help, but if you decide to use JavaScript, I can help. Maybe someone else who has used WebDAV will be able to assist you here.
Sep 15 '08 #5
OK, this is not JavaScript. It seems like you're using Web DAV. I have no experience of it, so can't be much help, but if you decide to use JavaScript, I can help. Maybe someone else who has used WebDAV will be able to assist you here.
Thanks for your reply. Really I'm new in "bytes". Can you recommend me, in which
forum may i become any tips to resolve my problem.

thank a lot.
Alireza
Sep 15 '08 #6
acoder
16,027 Expert Mod 8TB
Correct me if I'm wrong, but this seems like C++ code. If so, you can post in the C/C++ forum.
Sep 15 '08 #7
Correct me if I'm wrong, but this seems like C++ code. If so, you can post in the C/C++ forum.
Yes, it is and thanks for your effort. I do so.

Alieza
Sep 16 '08 #8
acoder
16,027 Expert Mod 8TB
OK, good luck in solving your problem.
Sep 16 '08 #9
rnd me
427 Expert 256MB
msxml4 is kinda crappy if i remember correctly.

ok, checked and i was right.

try using 6 or 3 instead.

check out the rundown on this page
Sep 16 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
1
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:
8
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....
0
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...
42
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...
9
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...
102
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...
5
by: will.hc.barker | last post by:
Am trying to set up a very simple AJAX script for my website. The javascript i have in an external file which reads as below. This works perfectly in firefox but IE doesn't display anything at...
2
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...
1
by: AlirezaShokoienia | last post by:
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.