Advertisement

04.29.2008 at 03:15PM PDT, ID: 23363837 | Points: 500
[x]
Attachment Details

Problem with HttpOpenRequest on Windows Mobile

Tags: Visual C++ embedded 4.0
I cannot make this code work. HttpOpenRequest returns NULL and GetLastError 87, but I can't figure out which parameter is supposedly wrong.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
void DownloadFile() 
{
	DWORD					status;
	CONNMGR_CONNECTIONINFO	connInfo;
	HANDLE					connHandle;
	HRESULT					hr;
	GUID					myGUID;
	DWORD					index;
	HANDLE					myReadyHandle;
	TCHAR					serverTest[255];
	TCHAR					m_sURL[1000];
	DWORD					dwConnStateFlags;
	BOOL					bRes;
	HINTERNET				hGETRequest;
	DWORD					dwFlags; 
	LPTSTR					pszAcceptTypes [] = {TEXT("text/*"), NULL}; 
	TCHAR					szServer [1024];
	TCHAR					szEndpoint [1024];
	URL_COMPONENTS			crackedURL;
	int						nPort;
	HINTERNET				hConnect;
	HINTERNET				hOpen;
	TCHAR					sHTTPHeader[500];
	hr=0;
	status=0;
	connHandle=0;
	index=0;
	myReadyHandle=0;
 
	wsprintf(m_sURL,_T("http://www.mysite.com/test.html"));
 
	memset(&myGUID, 0, sizeof(GUID));
	myReadyHandle = ConnMgrApiReadyEvent();
 
	if (WaitForSingleObject(myReadyHandle, 1000) != WAIT_OBJECT_0)
	{
		MessageBox(g_hwndMain, L"WaitForSingleObject.",L"",MB_OK);
		return;
	}
 
	CloseHandle(myReadyHandle);
 
	wsprintf(serverTest, _T("http://www.mysite.com"));
	hr = ConnMgrMapURL(serverTest, &myGUID, &index);
 
	memset(&connInfo, 0, sizeof(CONNMGR_CONNECTIONINFO));
	connInfo.cbSize			= sizeof(CONNMGR_CONNECTIONINFO);
	connInfo.dwParams		= CONNMGR_PARAM_GUIDDESTNET;
	connInfo.dwPriority		= CONNMGR_PRIORITY_USERINTERACTIVE;
	connInfo.bExclusive		= false;
	connInfo.bDisabled		= false;
	connInfo.guidDestNet	= myGUID;
 
	hr = ConnMgrEstablishConnectionSync(&connInfo, &connHandle, 30000, &status);
 
	if ( hr != S_OK )
	{
		MessageBox(g_hwndMain, L"Connection error.",L"",MB_OK);
		return;	
	}
 
 
	dwConnStateFlags = 0;
	bRes = InternetGetConnectedState(&dwConnStateFlags,0);
	if ( bRes ) 
	{
		wsprintf(g_tekst, L"ConnState = %X",dwConnStateFlags);
		MessageBox(g_hwndMain, g_tekst,L"",MB_OK);
	}
 
	dwFlags = INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_KEEP_CONNECTION | 
							  INTERNET_FLAG_IGNORE_CERT_CN_INVALID|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID|
						      INTERNET_FLAG_PRAGMA_NOCACHE; 
 
	ZeroMemory (& crackedURL, sizeof (URL_COMPONENTS));
	crackedURL.dwStructSize		= sizeof (URL_COMPONENTS);
	crackedURL.lpszHostName		= szServer;
	crackedURL.dwHostNameLength = 1024;
	crackedURL.lpszUrlPath		= szEndpoint;
	crackedURL.dwUrlPathLength	= 1024;
 
	InternetCrackUrl (m_sURL, 0, 0, &crackedURL);
	
	nPort = crackedURL.nPort;
 
	hOpen = InternetOpen (L"Felleskatalogen", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if ( !hOpen )
	{
		MessageBox(g_hwndMain, L"Failed to open WinInet",L"",MB_OK);
		return;
	}
	
	hConnect = InternetConnect (hOpen, szServer, nPort, L"", L"", INTERNET_SERVICE_HTTP, 0, 0);
	if ( !hConnect )
	{
		wsprintf(g_tekst, L"InternetConnect failed: %lu", GetLastError ());
		MessageBox(g_hwndMain, g_tekst,L"",MB_OK);
		return;
	}
 
	hGETRequest = HttpOpenRequest (hConnect, L"GET", szEndpoint, NULL, NULL, (LPCTSTR*) pszAcceptTypes, dwFlags, 0);
	if ( !hGETRequest )
	{
		wsprintf(g_tekst, L"HttpOpenRequest failed: %lu", GetLastError ());
		MessageBox(g_hwndMain, g_tekst,L"",MB_OK);
		InternetCloseHandle (hConnect);
		return;
	}
 
	wsprintf(sHTTPHeader, L"Content-Type: text/*\r\n");
	if (! HttpSendRequest (hGETRequest, (LPCTSTR) sHTTPHeader, -1, NULL, 0))
	{
		wsprintf(g_tekst, L"HttpSendRequest failed: %lu", GetLastError ());
		MessageBox(g_hwndMain, g_tekst,L"",MB_OK);
		InternetCloseHandle (hGETRequest);
		InternetCloseHandle (hConnect);
		return;
	}
 
	DWORD dwNumberOfBytesAvailable = 0;
	if ( InternetQueryDataAvailable(hGETRequest,&dwNumberOfBytesAvailable,0,0) )
	{
		wsprintf(g_tekst, L"File size is : %d",dwNumberOfBytesAvailable);
		MessageBox(g_hwndMain, g_tekst,L"",MB_OK);
	}
 
	char szBuffer[4096];
	DWORD dwNumberOfBytesRead = 0;
	TCHAR wszTmp[4097];
	int i = 0;
	DWORD dwTotal = 0;
	while ( InternetReadFile(hGETRequest, szBuffer, 4096,&dwNumberOfBytesRead) && dwNumberOfBytesRead )
	{
		memset(wszTmp,0,sizeof(wszTmp));
		MultiByteToWideChar(CP_ACP,0,szBuffer,dwNumberOfBytesRead,wszTmp,sizeof(wszTmp));
		i++;
		dwTotal += dwNumberOfBytesRead;
	}
	
	wsprintf(g_tekst,L"Read %d block(s) - %lu byte(s)",i,dwTotal);
	MessageBox(g_hwndMain, g_tekst,L"",MB_OK);
 
	InternetCloseHandle (hGETRequest);
	InternetCloseHandle (hConnect);
	InternetCloseHandle (hOpen);
}
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: kristianaustad
Question Asked On: 04.29.2008
Participating Experts: 1
Points: 500
Views: 0
Translate:
Loading Advertisement...
04.30.2008 at 05:14AM PDT, ID: 21469918

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.30.2008 at 05:45AM PDT, ID: 21470155

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
04.30.2008 at 05:45AM PDT, ID: 21470155
I've checked out the supplied link, it does not address this problem. There are no special characters in any of my URLs. No closer to a solution, unfortunately. InternetOpen and InternetConnect are successfull, but HttpOpenRequest fails. I think it must be due to some of the parameters passed (hence error code 87), but I don't know which.
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628