|
@@ -557,6 +557,74 @@ void CCurlClient::SetHeaders(const std::string headers)
|
|
|
m_headers = curl_slist_append(m_headers, headers.c_str());
|
|
|
}
|
|
|
|
|
|
+void CCurlClient::ParseURL(std::string url, UrlPars &pars)
|
|
|
+{
|
|
|
+ if ( url.size() == 0 )
|
|
|
+ return;
|
|
|
+
|
|
|
+ // 找头;
|
|
|
+ int len = 0;
|
|
|
+ int npos = url.find("https://");
|
|
|
+ if ( npos == std::string::npos ) {
|
|
|
+ npos = url.find("http://");
|
|
|
+ if ( npos != std::string::npos)
|
|
|
+ len = _tcslen("http://");
|
|
|
+ } else {
|
|
|
+ len = _tcslen("https://");
|
|
|
+ }
|
|
|
+
|
|
|
+ npos = url.find("/", len);
|
|
|
+ if ( npos == std::string::npos )
|
|
|
+ return;
|
|
|
+ pars.host = url.substr(0, npos);
|
|
|
+
|
|
|
+ // 找api;
|
|
|
+ len = npos+1;
|
|
|
+ npos = url.find("?", len);
|
|
|
+ if ( npos == std::string::npos )
|
|
|
+ return;
|
|
|
+ pars.api = url.substr(len, npos-len);
|
|
|
+
|
|
|
+ // 找pars;
|
|
|
+ len = npos + 1;
|
|
|
+ std::string strPars;
|
|
|
+ url = url.substr(npos+1);
|
|
|
+ while ( url.size() ) {
|
|
|
+ if ( (npos = url.find("&")) != std::string::npos ) {
|
|
|
+ strPars = url.substr(0, npos);
|
|
|
+ // 切换另一组;
|
|
|
+ url = url.substr(npos+1);
|
|
|
+
|
|
|
+ npos = strPars.find("=");
|
|
|
+ if ( npos != std::string::npos )
|
|
|
+ pars.pars.insert(std::pair<std::string,std::string>(strPars.substr(0, npos), strPars.substr(npos+1)));
|
|
|
+ } else {
|
|
|
+ strPars = url;
|
|
|
+ npos = strPars.find("=");
|
|
|
+ if ( npos != std::string::npos )
|
|
|
+ pars.pars.insert(std::pair<std::string,std::string>(strPars.substr(0, npos), strPars.substr(npos+1)));
|
|
|
+
|
|
|
+ // 结束;
|
|
|
+ url = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+std::string CCurlClient::ParseURLAndEncode(std::string url)
|
|
|
+{
|
|
|
+ UrlPars pars;
|
|
|
+ ParseURL(url, pars);
|
|
|
+ url = pars.host + "/" + pars.api + "?";
|
|
|
+ for ( std::map<std::string,std::string>::iterator it = pars.pars.begin(); it != pars.pars.end(); ) {
|
|
|
+ it->second = CharEncoding::EnCode_UTF8URL(it->second.c_str());
|
|
|
+ url.append(it->first+"="+it->second);
|
|
|
+ if ( (++it) != pars.pars.end() )
|
|
|
+ url.append("&");
|
|
|
+ }
|
|
|
+
|
|
|
+ return url;
|
|
|
+}
|
|
|
+
|
|
|
#if 0
|
|
|
bool CCurlClient::Download(const std::string& url, const std::string& path, long time_out /* = 3000 */)
|
|
|
{
|