Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy won't MFC::CHttpFile 'PUT' for me?
    primarykey
    data
    text
    <p>My code talks to a little Java application provided by a vendor. This Java app sets up a web server at localhost:57000 which is used to control the state of 'the machine'. For the purpose of this question, I need to change the state of 'the machine' from 'off' to 'on'. To make this happen I'm supposed to HTTP PUT the following string to 'the machine' at <a href="http://localhost:57000/settings.xml" rel="nofollow noreferrer">http://localhost:57000/settings.xml</a>:</p> <pre><code>&lt;settings&gt;&lt;machine_state&gt;&lt;status&gt;on&lt;/status&gt;&lt;/machine_state&gt;&lt;/settings&gt; </code></pre> <p>This Curl command works perfectly:</p> <p>curl -X PUT -H "Content-Type:application/xml" -d @settings.xml <a href="http://localhost:57000/settings.xml" rel="nofollow noreferrer">http://localhost:57000/settings.xml</a>"</p> <p>where the local file 'settings.xml' has the above xml string in it.</p> <p>I want to do what Curl is doing with MFC's WININET classes. The following code should IMHO do exactly the same thing that curl does. Sadly, although the localhost web server returns a code 200 it ignores my xml string. What little thing am I missing?</p> <pre><code>int MyHttp::HttpPutThread() NOTHROW { try { m_xml = "&lt;settings&gt;&lt;machine_state&gt;&lt;status&gt;on&lt;/status&gt;&lt;/machine_state&gt;&lt;/settings&gt;"; m_url = "settings.xml" CInternetSession session; SetSessionOptions(session); CString server = "localhost:57920"; boost::scoped_ptr&lt;CHttpConnection&gt; phttp(session.GetHttpConnection(server)); LPCTSTR accept = 0;//"text/xml"; boost::scoped_ptr&lt;CHttpFile&gt; phttpfile(phttp-&gt;OpenRequest( "PUT", //verb "settings.xml", //object name 0, //referer 1, //context &amp;accept, // accept types 0, //version INTERNET_FLAG_EXISTING_CONNECT)); CString header = "Content-Type:application/xml\r\n"; if(phttpfile-&gt;SendRequest(header,(LPVOID)m_xml.GetBuffer(), m_xml.GetLength())) { // LOG_DEBUG (Same as TRACE) output are shown in comment DWORD code(0); phttpfile-&gt;QueryInfoStatusCode(code); LOG_DEBUG("HttpPutThread result code: %d", code); // '200' CString object = phttpfile-&gt;GetObject(); LOG_DEBUG("object: %s", object); // 'settings.xml' CString statustxt; phttpfile-&gt;QueryInfo(HTTP_QUERY_STATUS_TEXT,statustxt); LOG_DEBUG("status text:%s", statustxt); // 'HTTP/1.0 200 OK' CString rawheaders; phttpfile-&gt;QueryInfo(HTTP_QUERY_RAW_HEADERS,rawheaders); LOG_DEBUG("raw headers:%s", rawheaders); // http://localhost:57000/settings.xml LOG_DEBUG("File url:%s",phttpfile-&gt;GetFileURL()); LOG_DEBUG("Verb:%s", phttpfile-&gt;GetVerb()); // 'PUT' } else { //This does not happen LOG_DEBUG("PUT failed in AffHttp::HttpPutThread"); } } catch(CInternetException* pe) { //No exceptions are thrown LOG_DEBUG("Exception HttpPutThread:%d", pe-&gt;m_dwError); pe-&gt;Delete(); } return 0; } </code></pre> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload