通过http协议给一个服务器地址传几个参数的值

wuyuwww 2014-08-28 12:40:31
我这边有一个关于给一个服务器传一个文件的代码
但是我不知道 怎么给一个服务器地址传一个参数 例如 URL:http://www.baidu.com?test=1&test2=name

我把我的部分代码贴一下
特别着急 求赐教!


CString strErrorMsg;
CString strURL;
GetDlgItem("IDC_EDIT1")->GetWindowText(strURL);
CString strParamName;
GetDlgItem("IDC_EDIT2")->GetDlgItemText(strParamName);
CString strParamValue;
GetDlgItem("IDC_EDIT3")->GetWindowText(strParamValue);
if(!strURL.IsEmpty())
{
int nResult = 5;
CInternetSession session(_T("HttpFilePOSTer"));
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
TCHAR szBuff[1024];
DWORD dwRet;
CFile file;
// if (!file.Open(strFileName, CFile::modeRead | CFile::shareDenyNone))
// {
// strErrorMsg = "打开文件失败";
// return 5;
// }

DWORD dwServiceType;
CString strServer, strObject, strUsername, strPassword;
INTERNET_PORT nPort;

if (AfxParseURLEx(strURL, dwServiceType, strServer, strObject, nPort, strUsername, strPassword) == FALSE)
{
strErrorMsg = "地址错误";
nResult = 1;
return ;
}

try
{
pServer = session.GetHttpConnection(strServer, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, strObject);//_T("/uploadfilepj/newfile.txt"));
TRACE(strObject);TRACE(_T("\n"));
pFile->SendRequestEx(file.GetLength());
// while (int nLen = file.Read(szBuff, 1024))
// {
// pFile->Write(szBuff, nLen);
// }
// file.Close();
// pFile->EndRequest();
// pFile->QueryInfoStatusCode(dwRet);
// file.Open(strResponsePage, CFile::modeCreate | CFile::modeWrite);
// while (int dwBuffLen = pFile->Read(szBuff, 1024))
// file.Write(szBuff, dwBuffLen);
// file.Close();
// if (dwRet == HTTP_STATUS_OK)
// {
// nResult = 0;
// strErrorMsg = "提交成功";
// }
// else
// {
// nResult = dwRet;
// strErrorMsg = "提交失败";
// }
}
catch (CInternetException* pEx)
{
nResult = 1;
pEx->GetErrorMessage(szBuff, 1024);
strErrorMsg = szBuff;
}


...全文
73 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧