📄 httpget.cpp
字号:
/** ** File ......... httpget.cpp ** Published .... 2004-04-07 ** Author ....... grymse@alhem.net**//*Copyright (C) 2004 Anders HedstromThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/#include <HttpGetSocket.h>#include <HttpsGetSocket.h>#include <SocketHandler.h>#include <Parse.h>bool Get(const std::string& url_in){ Parse pa(url_in,":/"); std::string protocol = pa.getword(); std::string host = pa.getword(); int port; { Parse pa(host,":"); pa.getword(); port = pa.getvalue(); } std::string url = "/" + pa.getrest(); std::string file; { Parse pa(url,"/"); std::string tmp = pa.getword(); while (tmp.size()) { file = tmp; tmp = pa.getword(); } } SocketHandler h; if (!strcasecmp(protocol.c_str(),"http")) { HttpGetSocket s(h,host,port ? port : 80,url,file); h.Add(&s); h.Select(1,0); while (h.GetCount()) { h.Select(1,0); } return s.Complete(); } else if (!strcasecmp(protocol.c_str(),"https")) { HttpsGetSocket s(h,host,port ? port : 443,url,file); h.Add(&s); h.Select(1,0); while (h.GetCount()) { h.Select(1,0); } return s.Complete(); } else { printf("Unknown protocol: '%s'\n",protocol.c_str()); } return false;}int main(int argc,char *argv[]){ for (int i = 1; i < argc; i++) { if (!Get(argv[i])) { printf("Failed: %s\n",argv[i]); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -