달력

52024  이전 다음

  • 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

'CHttpConnection 한글'에 해당되는 글 1건

  1. 2011.01.13 [c++] CHttpConnection에서 한글 전송 시 null 문제

CHttpConnection 을 이용해 asp 페이지로 한글을 보내고 이를 처리하는 과정에서 문제가 발생했다.
asp 페이지에 값이 null로 넘어옴으로 인해 데이터 처리가 불가능해지는 현상이었다..
이를 해결하기 위해 4시간여 구글링을 하면서 이것 저것 테스트 해본결과 성공적인 결과를 주는 한가지 셋팅을 찾아서 포스팅 한다..

1. 서버

기존 소스

char cpURL[128];
DWORD dwServiceType, dwRet;
INTERNET_PORT nPort;
CString ServerStr, ObjectStr, DataStr;
IString UserID, URL, Email, SQLComm, MSG;
BYTE BType;
int iError;

URL.Format("http://server.com/page.asp?id=%s&type=%d",UserID.ToChar(), BType);

sprintf(cpURL, "%s", URL.ToChar());
AfxParseURL(cpURL, dwServiceType, ServerStr, ObjectStr, nPort);
 
CString HeaderStr = "Content-Type: application/x-www-form-urlencoded";
CInternetSession Session("My Session", PRE_CONFIG_INTERNET_ACCESS);
CHttpConnection *pServer = NULL;
CHttpFile *pFile = NULL;

pServer = Session.GetHttpConnection(ServerStr, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, ObjectStr, 0, 1, 0, 0, INTERNET_FLAG_RELOAD);
pFile->AddRequestHeaders(HeaderStr);
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);
  
Session.Close();
delete pFile;
delete pServer;

==================================================
수정 소스

/// 우선 char를 UTF로 변경한다. 그리고 url은에서 파라미터는 제외 한다.
UserID.StringUtf8();    // *char를 utf8로 변경 (회사 내부 소스라 죄송;; 하지만 인터넷 뒤져 보면 나옴.)
URL.Format("
http://server.com/page.asp");
sprintf(cpURL, "%s", URL.ToChar());
AfxParseURL(cpURL, dwServiceType, ServerStr, ObjectStr, nPort);
/// 파라미터를 별도의 CStrig으로 저장
MSG.Format("id=%s&type=%d",UserID.ToChar(), BType); 
DataStr = (LPCTSTR)MSG.ToChar();
  
CString HeaderStr = "Content-Type: application/x-www-form-urlencoded";
CInternetSession Session("My Session", PRE_CONFIG_INTERNET_ACCESS);
CHttpConnection *pServer = NULL;
CHttpFile *pFile = NULL;

pServer = Session.GetHttpConnection(ServerStr, nPort);   // ServerStr =  http://server.com/
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, ObjectStr);   // ObjectStr = page.asp
pFile->SendRequest(HeaderStr,(LPVOID)(LPCTSTR)DataStr, DataStr.GetLength());  //DataStr = id=아이디&type=type
pFile->QueryInfoStatusCode(dwRet);



page.asp 소스에서
<% @language='vbscript' codepage = '65001' %>
<%      response.charset = "utf-8" %>
이 두줄을 추가한다.

=================================

수정 내용을 종합하면 Char* 를 UTF-8로 변경하고.
URL의 파라미터를 별도로 분리해서 SendRequest 에서 처리하고.
asp 에서는 UTF-8로 받는 소스를 추가...

이렇게 해서 해결됐다 !

'프로그래밍 > C++ / C' 카테고리의 다른 글

[C++/C] 트랜잭션 ...  (0) 2010.12.23
[C++/C] 중복되지 않게 랜덤 숫자 출력  (0) 2010.07.08
Posted by SadDev
|