Access HTTP files through proxy

Source: Internet
Author: User

Refer to the followingCode

// Download HTTP file through proxy

Cstring gehttptfile (cstring Surl)

{

Cstring scontent;

Char sproxylist [max_path], susername [64], spassword [64];

// In this case "proxya" is the proxy server name, and "8080" is its port

Strcpy (sproxylist, "proxya: 8080 ");

Strcpy (susername, "myusername ");

Strcpy (strpassword, "mypassword ");

DWORD dwservicetype = afx_inet_service_http;

Cstring sserver, sobject;

Internet_port nport;

Afxparseurl (URL, dwservicetype, szserver, szobject, nport );

Cinternetsession mysession;

Chttpconnection * pconnection;

Chttpfile * phttpfile;

Pconnection = mysession. gethttpconnection (szserver, internet_flag_keep_connection, internet_invalid_port_number, null, null );

Phttpfile = pconnection-> openrequest ("get", szobject, null, 0, null, null, internet_flag_keep_connection );

// Here for proxy

Internet_proxy_info proxyinfo;

Proxyinfo. dwaccesstype = internet_open_type_proxy;

Proxyinfo. lpszproxy = sproxylist;

Proxyinfo. lpszproxybypass = NULL;

Mysession. setoption (internet_option_proxy, (lpvoid) & proxyinfo, sizeof (internet_proxy_info ));

Phttpfile-> setoption (internet_option_proxy_username, susername, strlen (susername) + 1 );

Phttpfile-> setoption (internet_option_proxy_password, spassword, strlen (spassword) + 1 );

Phttpfile-> sendrequest (null );

DWORD nfilesize = phttpfile-> getlength ();

Lpstr rbuf = scontent. getbuffer (nfilesize );

Uint ubytesread = phttpfile-> Read (rbuf, nfilesize );

Scontent. releasebuffer ();

Phttpfile-> close ();

Delete phttpfile;

Pconnection-> close ();

Delete pconnection;

Mysession. Close ();

Return scontent;

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.