Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to make a CHttpFile::SendRequest, device hangs
    text
    copied!<p>I'm trying to fetch contents of an URL on a WM 6.5 not so uber gizmo, using VC++ 2008</p> <pre><code>CString http_request(CString params){ CInternetSession session(_T("My Session")); // add device identifier here? CHttpConnection* pServer = NULL; CHttpFile* pFile = NULL; CString szHeaders( _T("Content-Type: application/x-www-form-urlencoded;Accept: text/xml, text/plain, text/html, text/htm\r\nHost: www.mydomain.com\r\n\r\n")); CString strObject(""); CString out; DWORD dwRet; char *szBuff = new char[1023]; try { CString strServerName("www.mydomain.com"); INTERNET_PORT nPort(80); pServer = session.GetHttpConnection(strServerName, nPort); pFile = pServer-&gt;OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject); pFile-&gt;AddRequestHeaders(szHeaders); pFile-&gt;SendRequest(LPCTSTR(params),params.GetLength()); pFile-&gt;QueryInfoStatusCode(dwRet); if (dwRet == HTTP_STATUS_OK) { UINT nRead = pFile-&gt;Read(szBuff, 1023); while (nRead &gt; 0) { //read file... out = CString(szBuff); } } delete pFile; delete pServer; } catch (CInternetException* pEx) { //catch errors from WinInet out = CString("Something went wrong."); } session.Close(); return out; } </code></pre> <p>I do see the request coming in but the URI does not get passed, the server throws a 500 or 404 because of this. </p> <p>I've tried passing params as "GET /blah.txt HTTP/1.0" and also "/blah.txt", no luck, would like to keep testing various input parameters but the device hangs for some reason... </p> <p>Any pointers would be greatly appreciated!</p> <p>TIA</p> <p><strong>Later edit: Solution:</strong></p> <p>Here's how I got it to work, full code snippet in case anyone wants a copy paste solution (yeah these come in handy)</p> <pre><code>CString http_request(CString server, CString uri){ CInternetSession session(_T("My Session")); // add device identifier here? IMEI ftw CHttpConnection* pServer = NULL; CHttpFile* pFile = NULL; CString szHeaders( _T("Content-Type: application/x-www-form-urlencoded;Accept: text/xml, text/plain, text/html, text/htm\r\nHost: www.domain.com\r\n\r\n")); // maybe pass as param? CString strObject(uri); CString out; DWORD dwRet; CString params; char *szBuff = new char[1023]; try { CString strServerName(server); INTERNET_PORT nPort(80); pServer = session.GetHttpConnection(strServerName, nPort); pFile = pServer-&gt;OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject); pFile-&gt;AddRequestHeaders(szHeaders); pFile-&gt;SendRequest(szHeaders, szHeaders.GetLength(),&amp;params, params.GetLength()); pFile-&gt;QueryInfoStatusCode(dwRet); if (dwRet == HTTP_STATUS_OK) { UINT nRead = pFile-&gt;Read(szBuff, 1023); //while (nRead &gt; 0) //{ //read, for more data you might want to uncomment the while and append to a var. I only needed a few bytes actually. out = CString(szBuff); //} } else { out = CString("Communication error!"); } delete pFile; delete pServer; } catch (CInternetException* pEx) { //catch errors from WinInet out = CString("Network error!"); // stupid a$$ cpp the code to handle this would be longer than my **** } session.Close(); pServer-&gt;Close(); return out; } </code></pre>
 

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