读书人

WinInet模拟html,Post数据的有关问题

发布时间: 2012-02-15 12:09:44 作者: rapoo

高手进,WinInet模拟html,Post数据的问题。
有这样一个html文件,用httpRequest模拟Post
<form action= "http://www.test.com/client/upload.php " method= "post " name= "form1 " enctype= "multipart/form-data ">
<table width= "90%% " border= "0 ">
<tr>
<td width= "120 "> 电话号码: </td>
<td> <input name= "telnum " type= "text " id= "telnum "> </td>
</tr>
<tr>
<td> 密码: </td>
<td> <input name= "password " type= "password " id= "password "> </td>
</tr>
<tr>
<td> 标题: </td>
<td> <input name= "title " type= "text " id= "title "> </td>
</tr>
<tr>
<td> 描述: </td>
<td> <input name= "intro " type= "text " id= "intro "> </td>
</tr>
<tr>
<td> 内容类型: </td>
<td> <select name= "catalog " id= "catalog ">
<option value= "1 " selected> 翻唱内容 </option>
<option value= "2 "> 个性化语音 </option>
<option value= "3 "> 音乐编辑内容 </option>
</select> </td>
</tr>
<tr>
<td> 彩铃文件: </td>
<td> <input name= "ringfile " type= "file " id= "ringfile "> </td>
</tr>
<tr>
<td colspan= "2 "> <input name= "submit " type= "submit " value= "提交 "> </td>
</tr>
</table>
</form>

/////////////////////////////////////////////////////////////////////
代码如下:高手看下,那里有错误,执行不成功:
CFile theFile;
if(!theFile.Open(strpath,CFile::modeRead))return false;

CInternetSession session;
CHttpConnection* pConnection = session.GetHttpConnection(_T( "music.telinclub.cn "));


CHttpFile* pFile = pConnection-> OpenRequest(CHttpConnection::HTTP_VERB_POST, "/client/diyRing_upload.php ");
CString strHttpHead = _T( "Accept: */*\rContent-Type: multipart/form-data;boundary=-----------------------------7d2227629012e ");
BOOL bTrue = pFile-> AddRequestHeaders(strHttpHead);

// add the other
CString strInput = "-----------------------------7d2227629012e\r\nContent-Disposition: form-data; name=\ "telnum\ "\r\n\r\n ";
strInput += strNum;
strInput += "\r\n-----------------------------7d2227629012e\r\nContent-Disposition: form-data; name=\ "password\ "\r\n\r\n ";
strInput += pwd;
strInput += "\r\n-----------------------------7d2227629012e\r\nContent-Disposition: form-data; name=\ "title\ "\r\n\r\n ";
strInput += strTitle;
strInput += "\r\n-----------------------------7d2227629012e\r\nContent-Disposition: form-data; name=\ "intro\ "\r\n\r\n ";
strInput += strDest;
strInput += "\r\n-----------------------------7d2227629012e\r\nContent-Disposition: form-data; name=\ "catalog\ "\r\n ";
strInput += strtype;
strInput += "\r\n-----------------------------7d2227629012e\r\nContent-Disposition: form-data; name=\ "ringfile\ ";filename=\ " ";
strInput += strpath;
strInput += "\ "\r\nContent-Type: audio/wma\r\n\r\n ";

CString strEnd = "-----------------------------7d2227629012e--\r\n ";
ULONGLONG uSendLen =strInput.GetLength();
uSendLen += strHttpHead.GetLength();
uSendLen += theFile.GetLength();
uSendLen += strEnd.GetLength();


//先写文本
bTrue = pFile-> SendRequestEx(uSendLen);
pFile-> Write(strInput,strInput.GetLength());

//再传文件
char szBuf[8192]={0};
int nRead = 0;
while(true)
{
nRead = theFile.Read(szBuf,8192);
if(nRead < 1)break;
pFile-> Write(szBuf,nRead);
}
theFile.Close();

pFile-> Write(strEnd,strEnd.GetLength());

DWORD dwRet=0;
bTrue = pFile-> QueryInfoStatusCode(dwRet);
if(dwRet == HTTP_STATUS_OK)
{
char szbuf[256]={0};
int nlen = pFile-> Read(szbuf,255);
szbuf[nlen-1]= '\0 ';
int nret = atoi(szbuf);
switch(nret)
{
case 1:
break;
case 0:
break;
}
}
pFile-> Close();
pConnection-> Close();
delete pFile;
delete pConnection;
session.Close();
return true;


[解决办法]
关阵子研究过post
[解决办法]
我来了...前段时间已经把这个问题搞清楚了,嘿嘿

读书人网 >VC/MFC

热点推荐