post数据的时候“+”号被替换成空格了.该怎么解决
1个回答
展开全部
试的时候可以看到post的数据里面是有“+”号的,但是用截包工具(HttpAnalyzer)截到的数据里面“+”全部被替换成空格了。。。这是什么问题呢。。我post数据的函数代码如下:
C/C++ code
BOOL PostData(const char *szUrl,const char *szContent,CString &strResult)
{
static const char *hdrs = "Content-Type: application/x-www-form-urlencoded";
static const char *acpt = "acpt: */*";
BOOL bRet = TRUE;
strResult="";
HINTERNET hInternet = InternetOpen("PostData",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
if(hInternet!=NULL)
{
URL_COMPONENTS UrlComponents;
memset(&UrlComponents,0,sizeof(UrlComponents));
UrlComponents.dwStructSize=sizeof(UrlComponents);
UrlComponents.dwHostNameLength=64;
char szHostName[64];
UrlComponents.lpszHostName=szHostName;
UrlComponents.dwUrlPathLength=256; // length of URL-path
InternetCrackUrl(szUrl,0,0,&UrlComponents);
UrlComponents.lpszHostName[UrlComponents.dwHostNameLength]=0;
HINTERNET hConnect = InternetConnect(hInternet, UrlComponents.lpszHostName, UrlComponents.nPort, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if(hConnect!=NULL)
{
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", UrlComponents.lpszUrlPath, NULL, NULL, &acpt, 0, 1);
if(hRequest!=NULL)
{
HttpSendRequest(hRequest, hdrs, strlen(hdrs), (void *)szContent,strlen(szContent));
char pBuf[4096];
DWORD dwMaxDataLength=4096;
DWORD dwReadDataLength=0;
DWORD dwReadLength;
memset(pBuf,0,4096);
while(InternetReadFile(hRequest,pBuf,dwMaxDataLength,&dwReadLength)&&dwReadLength!=0)
{
strResult+=pBuf;
memset(pBuf,0,4096);
}
InternetCloseHandle(hRequest);
}
else
{
bRet = FALSE;
}
InternetCloseHandle(hConnect);
}
else
{
bRet = FALSE;
}
InternetCloseHandle(hInternet);
}
return bRet;
}
C/C++ code
BOOL PostData(const char *szUrl,const char *szContent,CString &strResult)
{
static const char *hdrs = "Content-Type: application/x-www-form-urlencoded";
static const char *acpt = "acpt: */*";
BOOL bRet = TRUE;
strResult="";
HINTERNET hInternet = InternetOpen("PostData",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
if(hInternet!=NULL)
{
URL_COMPONENTS UrlComponents;
memset(&UrlComponents,0,sizeof(UrlComponents));
UrlComponents.dwStructSize=sizeof(UrlComponents);
UrlComponents.dwHostNameLength=64;
char szHostName[64];
UrlComponents.lpszHostName=szHostName;
UrlComponents.dwUrlPathLength=256; // length of URL-path
InternetCrackUrl(szUrl,0,0,&UrlComponents);
UrlComponents.lpszHostName[UrlComponents.dwHostNameLength]=0;
HINTERNET hConnect = InternetConnect(hInternet, UrlComponents.lpszHostName, UrlComponents.nPort, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if(hConnect!=NULL)
{
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", UrlComponents.lpszUrlPath, NULL, NULL, &acpt, 0, 1);
if(hRequest!=NULL)
{
HttpSendRequest(hRequest, hdrs, strlen(hdrs), (void *)szContent,strlen(szContent));
char pBuf[4096];
DWORD dwMaxDataLength=4096;
DWORD dwReadDataLength=0;
DWORD dwReadLength;
memset(pBuf,0,4096);
while(InternetReadFile(hRequest,pBuf,dwMaxDataLength,&dwReadLength)&&dwReadLength!=0)
{
strResult+=pBuf;
memset(pBuf,0,4096);
}
InternetCloseHandle(hRequest);
}
else
{
bRet = FALSE;
}
InternetCloseHandle(hConnect);
}
else
{
bRet = FALSE;
}
InternetCloseHandle(hInternet);
}
return bRet;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询