首页IT科技Download chrome apk(download a file from a url in C++ Ubuntu Forums)

Download chrome apk(download a file from a url in C++ Ubuntu Forums)

时间2025-08-05 01:42:00分类IT科技浏览5559
导读:Heres a C version....

Heres a C version.
PHP Code:

/*

*wget_sortof.c

*

*Copyright2007VyacheslavGoltser

*

*Thisprogramisfreesoftware;youcanredistributeitand/ormodify

*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby

*theFreeSoftwareFoundation;eitherversion2oftheLicense,or

*(atyouroption)anylaterversion.

*

*Thisprogramisdistributedinthehopethatitwillbeuseful,

*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof

*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe

*GNUGeneralPublicLicenseformoredetails.

*

*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense

*alongwiththisprogram;ifnot,writetotheFreeSoftware

*Foundation,Inc.,51FranklinStreet,FifthFloor,Boston,MA02110-1301,USA.

*/

/*getthemainpagefromgoogle.com*/

#include

#include

#include

#include

#include

#include

#include

#include<unistd.h>

intmain(intargc,char**argv

)

{

structsockaddr_inservaddr

;

structhostent*hp

;

intsock_id

;

charmessage[1024*1024]={0

};

intmsglen

;

charrequest[]=

"GET/index.htmlHTTP/1.0\n"

"From:slava!!!\nUser-Agent:wget_sortofbyslava\n\n"
;

//Getasocket

if((sock_id=socket(AF_INET,SOCK_STREAM,0))==-1

){

fprintf(stderr,"Couldntgetasocket.\n");exit(EXIT_FAILURE

);

}

else{

fprintf(stderr,"Gotasocket.\n"

);

}

//bookusesbzerowhichmymanpagessayisdeprecated

//themanpagesaidtousememsetinstead.:-)

memset(&servaddr,0,sizeof(servaddr));

//getaddressforgoogle.com

if((hp=gethostbyname("google.com"))==NULL

){

fprintf(stderr,"Couldntgetanaddress.\n");exit(EXIT_FAILURE

);

}

else{

fprintf(stderr,"Gotanaddress.\n"

);

}

//bcopyisdeprecatedalso,usingmemcpyinstead

memcpy((char*)&servaddr.sin_addr.s_addr,(char*)hp->h_addr,hp->h_length);

//fillintportnumberandtype

servaddr.sin_port=htons(80

);

servaddr.sin_family=AF_INET;

//maketheconnection

if(connect(sock_id,(structsockaddr*)&servaddr,sizeof(servaddr))!=0

){

fprintf(stderr,"Couldntconnect.\n"

);

}

else{

fprintf(stderr,"Gotaconnection!!!\n"

);

}

//NOWTHEHTTPPART!!!

//sendtherequest

write(sock_id,request,strlen(request));

//readtheresponse

msglen=read(sock_id,message,1024*1024);

printf("responseis%dbyteslong\n",msglen);

//printthereasponse

printf("%s",message);

return0

;

}
__________________

I am infallible, you should know that by now.

"My favorite language is call STAR. Its extremely concise. It has exactly one verb *, which does exactly what I want at the moment." --Larry Wall

(02:15:31 PM) ***TimToady and snake oil go way back...

42 lines of Perl - SHI - Home Site

声明:本站所有文章             ,如无特殊说明或标注                    ,均为本站原创发布              。任何个人或组织       ,在未征得本站同意时       ,禁止复制              、盗用                    、采集      、发布本站内容到任何网站              、书籍等各类媒体平台                    。如若本站内容侵犯了原著者的合法权益                    ,可联系我们进行处理      。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
freemarker动态生成word表格(使用Freemarker来生成pdf文件)