当前位置: 技术问答>linux和unix
url编码的问题。
来源: 互联网 发布时间:2016-11-05
本文导语: 我用c++写了一个自动发送请求的程序。 //请求头 CString boundary = "----WebKitFormBoundaryZVqWse5n5jI83Nms"; renren_header.Empty(); renren_header += _T("Host: msg.renren.comrn") ; renren_header += _T("Accept: application/xml,application/xhtml+xml,text/ht...
我用c++写了一个自动发送请求的程序。
//请求头
CString boundary = "----WebKitFormBoundaryZVqWse5n5jI83Nms";
renren_header.Empty();
renren_header += _T("Host: msg.renren.comrn") ;
renren_header += _T("Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5rn") ;
renren_header += _T("Accept-Language: zh-cnrn") ;
renren_header += _T("User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)rn") ;
renren_header += _T("Accept-Encoding: gzip,deflate,sdchrn");
renren_header += _T("Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3rn");
renren_header += _T("Origin: http://msg.renren.comrn");
renren_header += _T("Connection: Keep-Alivern");
renren_header += (_T("Content-Type: multipart/form-data; boundary=") + boundary + ("rn"));
renren_header += _T("Cache-Control: max-age=0rn");
renren_header += _T("Referer: http://msg.renren.com/message/compose.do?ref=trn");
//g_biz
g_biz = "949_8000848107201560600";
CString _friend_name = "%E5%BC%A0%E5%BA%86";
//types
strFormData.Empty();
strFormData += (("--") + boundary + ("rn")); //first boundary
#if 1
strFormData += (_T("Content-Disposition: form-data; name="types[]"rnrn0"));
//ids
strFormData += ("rn--")+ boundary +("rn"); // boundary
#endif
strFormData += (_T("Content-Disposition: form-data; name="ids[]"rnrn") + _friend_id);
#if 1
//names
strFormData += ("rn--")+ boundary +("rn"); // boundary
strFormData += (_T("Content-Disposition: form-data; name="names[]"rnrn") + _friend_name);
//emails
strFormData += ("rn--") + boundary +("rn"); // boundary
strFormData += (_T("Content-Disposition: form-data; name="emails[]"rnrn"));
#endif
//etypes
strFormData += ("rn--") + boundary +("rn"); // boundary
strFormData += (_T("Content-Disposition: form-data; name="etypes[]"rnrn0") );
//subject
strFormData += ("rn--") + boundary +("rn"); //first boundary
strFormData += (_T("Content-Disposition: form-data; name="subject"rnrn") + _subject); //subject
//message
strFormData += ("rn--") + boundary +("rn"); //boundary
strFormData += (_T("Content-Disposition: form-data; name="message"rnrn") + _status);
#if 1
//biz
strFormData += ("rn--") + boundary +("rn"); //boundary
strFormData += (_T("Content-Disposition: form-data; name="biz"rnrn") + g_biz);
#endif
//requestToken get_check截取到的内容是这个token
strFormData += ("rn--") + boundary +("rn"); //boundary
strFormData += (_T("Content-Disposition: form-data; name="requestToken"rnrn") + g_get_check );
printf("the requestToken:%sn", (LPVOID)(LPCTSTR)g_get_check);
strFormData +=("rn--") + boundary +("--rn"); //boundary
try
{
strObject=_T("/message/send.do");
//strObject +=_T("&origURL=http%3A%2F%2Fmsg.renren.com%2Fmessage%2Fcompose.do%3Fref%3Dt");
//pServer = g_Session_HG.GetHttpConnection(strServer,nPort);
g_pFile = g_pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST ,strObject);
g_pFile->SendRequest(renren_header,(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
//pFile->SendRequest(renren_header,(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
}
catch(CInternetException *e)
{
char error[127];
e->GetErrorMessage(error,127);
return false;
}
tem_lineBuf.Empty();
g_pFile->ReadString(tem_lineBuf);
请求的内容是所有的汉字必须以url编码的形式提交,例如,不知道怎么转啊,不知道啊
//请求头
CString boundary = "----WebKitFormBoundaryZVqWse5n5jI83Nms";
renren_header.Empty();
renren_header += _T("Host: msg.renren.comrn") ;
renren_header += _T("Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5rn") ;
renren_header += _T("Accept-Language: zh-cnrn") ;
renren_header += _T("User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)rn") ;
renren_header += _T("Accept-Encoding: gzip,deflate,sdchrn");
renren_header += _T("Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3rn");
renren_header += _T("Origin: http://msg.renren.comrn");
renren_header += _T("Connection: Keep-Alivern");
renren_header += (_T("Content-Type: multipart/form-data; boundary=") + boundary + ("rn"));
renren_header += _T("Cache-Control: max-age=0rn");
renren_header += _T("Referer: http://msg.renren.com/message/compose.do?ref=trn");
//g_biz
g_biz = "949_8000848107201560600";
CString _friend_name = "%E5%BC%A0%E5%BA%86";
//types
strFormData.Empty();
strFormData += (("--") + boundary + ("rn")); //first boundary
#if 1
strFormData += (_T("Content-Disposition: form-data; name="types[]"rnrn0"));
//ids
strFormData += ("rn--")+ boundary +("rn"); // boundary
#endif
strFormData += (_T("Content-Disposition: form-data; name="ids[]"rnrn") + _friend_id);
#if 1
//names
strFormData += ("rn--")+ boundary +("rn"); // boundary
strFormData += (_T("Content-Disposition: form-data; name="names[]"rnrn") + _friend_name);
//emails
strFormData += ("rn--") + boundary +("rn"); // boundary
strFormData += (_T("Content-Disposition: form-data; name="emails[]"rnrn"));
#endif
//etypes
strFormData += ("rn--") + boundary +("rn"); // boundary
strFormData += (_T("Content-Disposition: form-data; name="etypes[]"rnrn0") );
//subject
strFormData += ("rn--") + boundary +("rn"); //first boundary
strFormData += (_T("Content-Disposition: form-data; name="subject"rnrn") + _subject); //subject
//message
strFormData += ("rn--") + boundary +("rn"); //boundary
strFormData += (_T("Content-Disposition: form-data; name="message"rnrn") + _status);
#if 1
//biz
strFormData += ("rn--") + boundary +("rn"); //boundary
strFormData += (_T("Content-Disposition: form-data; name="biz"rnrn") + g_biz);
#endif
//requestToken get_check截取到的内容是这个token
strFormData += ("rn--") + boundary +("rn"); //boundary
strFormData += (_T("Content-Disposition: form-data; name="requestToken"rnrn") + g_get_check );
printf("the requestToken:%sn", (LPVOID)(LPCTSTR)g_get_check);
strFormData +=("rn--") + boundary +("--rn"); //boundary
try
{
strObject=_T("/message/send.do");
//strObject +=_T("&origURL=http%3A%2F%2Fmsg.renren.com%2Fmessage%2Fcompose.do%3Fref%3Dt");
//pServer = g_Session_HG.GetHttpConnection(strServer,nPort);
g_pFile = g_pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST ,strObject);
g_pFile->SendRequest(renren_header,(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
//pFile->SendRequest(renren_header,(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
}
catch(CInternetException *e)
{
char error[127];
e->GetErrorMessage(error,127);
return false;
}
tem_lineBuf.Empty();
g_pFile->ReadString(tem_lineBuf);
请求的内容是所有的汉字必须以url编码的形式提交,例如,不知道怎么转啊,不知道啊
|
参考http://meyerweb.com/eric/tools/dencoder/
|
参考 http://ynhu33.blog.51cto.com/412835/405174
与 http://www.micronsky.com/2008/07/linux-shell-encode-url/
可以看下od的实现,或者直接使用下这个工具
...
与 http://www.micronsky.com/2008/07/linux-shell-encode-url/
可以看下od的实现,或者直接使用下这个工具
...