본문 바로가기

Windows/MFC

GPRS Conection via Proxy

http://bullychen.blogspot.com/2009/07/windows-mobile-gprs-connection-via.html

1. APN connect
lResult = ConnMgrMapConRef(ConRefType_NAP,APN_Name, &guidNetwork);

CONNMGR_CONNECTIONINFO ConnInfo;
ConnInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP | CONNMGR_FLAG_PROXY_WAP | CONNMGR_FLAG_PROXY_SOCKS4 | CONNMGR_FLAG_PROXY_SOCKS5;
ConnInfo.xxx= xxxx... ;
HRESULT hResult = ConnMgrEstablishConnectionSync(&ConnInfo, &phConnection, 10*1000, &dwStatus );
if( FAILED(hResult))
Add_Log(hWnd, _T("Connected failed!! Please retry your connection..."));
else{
Add_Log(hWnd, _T("APN connected!!"));
hResult = ConnMgrConnectionStatus(phConnection,&dwStatus);
if (dwStatus == CONNMGR_STATUS_CONNECTED) {
Add_Log(hWnd, _T("Internet connection succesfully completed."));
}
}

2. Set the internet open type:
hHttpOpen = InternetOpen( L"Test",
INTERNET_OPEN_TYPE_PROXY, // use proxy tag
L"http://xx.xx.xx.xx:5408", // [proxy url]:[port]
0,
0 );

3. Open a HTTP session for a given site:
hHttpSession = InternetConnect( hHttpOpen,
(LPCWSTR)L"mmm.mmm.mmm.mmm", // dest host, 如 www.mobile01.com
5978, // dest port number
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
0 );

4. Creates an HTTP request handle:
hHttpRequest = HttpOpenRequest( hHttpSession,
(LPCWSTR)L"GET",
(LPCWSTR)L"/xxx/xxx/xxx.xxx",//target in host, 如 /index.php
HTTP_VERSION,
NULL,
NULL,
INTERNET_FLAG_DONT_CACHE,
0 );


5. Sends the specified request to the HTTP server:
if(!HttpSendRequest( hHttpRequest,NULL, 0, NULL, 0))
{
Add_Log(hWnd, _T(" HttpSendRequest Failed! (%x)\n", GetLastError()));
InternetCloseHandle(hHttpOpen);
InternetCloseHandle(hHttpSession);
InternetCloseHandle(hHttpRequest);
return false;
}

6. Retrieves header information associated with an HTTP request:
HttpQueryInfo ( hHttpRequest,
HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
&dwStatus,
&dwLengthSizeBuffer,
NULL );
if (dwStatus == 404)
Add_Log(hWnd,_T(" Connection Failed."));
else if (dwStatus == 200)
Add_Log(hWnd,_T(" Succeed."));
else
Add_Log(hWnd,_T(" Unknown Response."));

wchar_t errorMsg[20]={0};
wsprintf(errorMsg, L"Response:: %u", dwStatus);
Add_Log(hWnd,errorMsg);

'Windows > MFC' 카테고리의 다른 글

Cellular Emulator  (0) 2013.10.02
Using Connection Manager to Establish Data Calls  (0) 2013.10.02
GPRS connection  (0) 2013.10.02
Cellular Emulator사용하기  (0) 2013.10.02
SMS Send  (0) 2013.10.02