Use wininet to implement HTTP protocol

Source: Internet
Author: User
Tags solr

// Get Method

# Include <windows. h>
# Include <wininet. h>
# Include <stdio. h>

# Pragma comment (Lib, "wininet. lib ")

Int main ()
{
Hinternet = internetopena ("testing", internet_open_type_direct, null, null, 0); // initialize wininet
Hinternet hconnect = internetconnecta (hinternet, "www.google.com.hk", internet_default_http_port,
Null, null, internet_service_http, 0, 0); // connect to the server
Hinternet hopenrequest = httpopenrequesta (hconnect, "get", "/advanced_search? Hl = ZH-CN ", null, null,
(Lpcstr *) "*/*", internet_flag_dont_cache, 1); // create an HTTP request
Bool brequest = httpsendrequesta (hopenrequest, null, 0, null, 0); // send an HTTP request
Char szbuffer [1024] = {0 };
DWORD dwbyteread = 0;
File * fp = NULL;
Fopen_s (& FP, "1.html", "W ");
While (internetreadfile (hopenrequest, szbuffer, sizeof (szbuffer), & dwbyteread) & dwbyteread> 0)
{
Fwrite (szbuffer, dwbyteread, 1, FP );
Zeromemory (szbuffer, dwbyteread );
}
Fclose (FP );
Return 0;
}

 

// POST method

# Include <windows. h>
# Include <wininet. h>
# Include <stdio. h>

# Pragma comment (Lib, "wininet. lib ")

Int main ()
{
/*
Open the webpage adresrchcache82/SOLR/select? Indent = on & version = 2.2 & Q = California + 0p1_gluk + 157498 + California % 70l00000122 + fsusa04car + California % 70l00000138 + California + 558658 + f0can062as % 70l00000138% 7cu % 24% 24% 24% 24% 24gbl + 0000% 70l00000204 + f0000007t0 + 0000+ 0000+ 0000% 0000+ 528765 + 0000+ f000000l2b % 0000% 7cu % 24% 24% 24% 24gbl + 0p0000mvdx + 0p0000ieqq + fousa099m0 + listen + 348213 + 0p0000iqg3 + f0gbr06gcz % 70l00000138% 7cu % 24% 24% 24% 24% 24gbl + 333451 + weight + 327788 + weight % 70l00000122 + weight + 446351 + 0p000068zr + f000001bmp %%70l00000135% 7cu % 24% 24% 24% 24% 24gbl + f000002lhe + f0000020.p6 + signature % 70l00000138% 7cu % 24% 24% 24% 24gbl + fsusa04car + signature + %% 70l00000408 + f00000jxce + 240215 + f00000048u + 531508 + %+ fsusa07lov + %70l00000138% 7cu % 24% 24% 24% 24% 24can + fsusa07rov + %+ %% 70l00000122 + %+ fsusa0a0nm + %+ 301470 + 400069 + f00000hdpd + %+ fsusa07wen + %+ fsusa0anrk + %+ 0p%acye + f000005m0x + %+ 14638 + %+ 459295 cost + 460158 + fsusa04aka % Percent + percent % 70l00000408 + percent + 0p0000ru6a + percent % 70l00000122 + 266704 + percent % 70l00000138% 7cu % 24% 24% 24% 24gbl + 490407 + records % 70l00000122 + 518557 + 292372 + records + f0gbr055ov % 70l00000138% 7cu % 24% 24% 24% 24gbl + fousa097gp + records % 70l00000152 + 24% + Records & FQ = & START = 0 & rows = 100 & FL = pm001 + st735 + pm02h + ca516 + rr00h + os38a + hs000 + hs04q + pm00k + hs002 + das0n + pm02f + das29 + pm513 + das0t + hs00c + large + das25 + pm02g + pm00k + hs004 + large + pm448 + pm461 + hs08o + hs006 + large + pm013 + pm455 + pm00a + pm140 + aa0aq + rr011 + hs04s + st153 + das03 + pm004 + das0i + hs08l + hs00v + das34 + large + hs02a + das05 + rr015 + large + rr03a + hs07s + st735 + hs157 + das30 + pm02d + rr01u + aa03n + hs04a + das36 + pm140 + pm528 + hs148 + pm142 + das41 + of00h + aa03n + pm522 + large + pm1_+ large + pm428 + das33 + pm00i + pm00i + hs05e + pm541 + das21 + os687 + large + large + rr01e + das39 + pm457 + rr00m + hs079 + hs02i + das35 + pm008 + pm581 + pm00e + pm457 + das21 + hs04c + aa0a8 + das07 + os384 + hs004 + rr002 + large + pm00o + hs02i + das29 + pm00v + large + hs092 + pm00q + st735 + large + pm425 + os05j + pm00q + das37 + aa03r + os050 + das31 + hs02l + hs06h + rr102 + large + pm006 + das0b + hs078 + aa03r + os463 + ca514 + st154 + das15 + hs00v + pm426 + hs06k + das30 + das0e + das22 + pm00q + pm458 + large + das32 + large + pm00y + pm461 + pm58b + aa0f3 + das06 + das35 + os050 + das31 + rr03a + aa03q + os076 + hs03i + rr00m & Qt = Standard & Wt = Standard & explainother = & Hl. FL =
*/
Hinternet = internetopena ("testing", internet_open_type_direct, null, null, 0); // initialize wininet
Char strsever [] = "adresrchcache82 ";
Hinternet hconnect = internetconnecta (hinternet, strsever, internet_default_http_port,
Null, null, internet_service_http, 0, 0); // connect to the server
Char strobject [] = "/SOLR/select ";
Hinternet hopenrequest = httpopenrequesta (hconnect, "Post", strobject, null, null,
(Lpcstr *) "*/*", internet_flag_dont_cache, 1); // create an HTTP request
Char HDRs [] = "Content-Type: Application/X-WWW-form-urlencoded ";
Char options [] = "indent = on & version = 2.2 & Q = large + 0p1_gluk + 157498 + large % 70l00000122 + fsusa04car + 0p1_j395 + large % 70l00000138 + large + 558658 + f0can062as % %% 7cu % 24% 24% 24% 24% 24gbl + %% 70l00000204 + f%007t0 + %+ %% 70l00000122 + 528765 + %+ f%00l2b % 70l00000138% 7cu % 24% 24% 24% 24gbl + 0p1_mvdx + 0p1_ieqq + fousa099m0 + large + 348213 + 0p1_iqg3 + large % 70l00000138% 7cu % 24% 24% 24% 24% 24gbl + 333451 + large + 327788 + large % 70l00000122 + large + 446351 + 0p000068zr + f000001bmp + capacity % 70l00000135% 7cu % 24% 24% 24% 24% 24% 24gbl + capacity + f000000000p6 + capacity % 70l00000138% 7cu % 24% 24% 24% 24gbl + fsusa04car + hour % 70l00000408 + f00000jxce + 240215 + f00000048u + 531508 + hour + fsusa07lov + hour % 7cu % 24% 24% 24% 24can + fsusa07rov + hour percent + percent % 70l00000122 + percent + fsusa0a0nm + percent + 0p00007xvn + 301470 + 400069 + f00000hdpd + percent + fsusa07wen + percent + fsusa0anrk + percent + 0p0000acye + percent 14638 + records + 459295 + records + 460158 + fsusa04aka % 70l00000122 + records % 70l00000408 + records + 0p0000ru6a + records % 70l00000122 + 266704 + records % 70l00000138% 7cu % 24% 24% 24% 24% 24gbl + 490407 + fsusa08hro % 70l00000122 + 518557 + 292372 + records % 70l00000138% 7cu % 24% 24% 24% 24% 24gbl + fousa097gp + records % 70l00000152 + 462878 + records & FQ = & START = 0 & rows = 100 & FL = pm001 + st735 + pm02h + ca516 + rr00h + os38a + hs000 + hs04q + pm00k + hs002 + das0n + pm02f + das29 + pm513 + signature + hs00c + hs03c + das25 + pm02g + pm00k + hs004 + das0p + pm448 + pm461 + hs08o + hs006 + pm00i + pm013 + pm455 + pm00a + pm140 + aa0aq + signature + + st153 + das03 + pm004 + das0i + hs08l + hs00v + das34 + os020 + large + das05 + rr015 + pm142 + st735 + large + hs07s + st735 + hs157 + das30 + pm02d + rr01u + large + hs04a + das36 + pm140 + pm528 + hs148 + pm142 + das41 + of00h + aa03n + pm522 + os01x + pm1_+ pm151 + pm428 + das33 + pm00i + pm00i + large + das21 + os687 + rr01t + pm58b + large + das39 + pm457 + rr00m + hs079 + large + das35 + pm008 + pm581 + pm00e + pm457 + das21 + hs04c + aa0a8 + das07 + os384 + hs004 + rr002 + rr00i + pm00o + large + das29 + pm00v + hs081 + large + st735 + hs06e + rr00i + pm425 + os05j + pm00q + das37 + aa03r + os050 + das31 + large + hs06h + rr102 + hs08o + pm006 + das0b + hs078 + aa03r + os463 + ca514 + st154 + das15 + hs00v + pm426 + hs06k + das30 + das0e + das22 + large + pm02d + das32 + pm481 + pm00y + pm461 + pm58b + aa0f3 + das06 + das35 + os050 + das31 + rr03a + aa03q + os076 + hs03i + rr00m & Qt = Standard & Wt = Standard & amp; explainother = & Hl. FL = ";
Bool brequest = httpsendrequesta (hopenrequest, HDRs, (DWORD) strlen (HDRs), options, (DWORD) strlen (options); // send an HTTP request
Char szbuffer [1024] = {0 };
DWORD dwbyteread = 0;
File * fp = NULL;
Fopen_s (& FP, "1.xml"," W ");
While (internetreadfile (hopenrequest, szbuffer, sizeof (szbuffer), & dwbyteread) & dwbyteread> 0)
{
Fwrite (szbuffer, dwbyteread, 1, FP );
Zeromemory (szbuffer, dwbyteread );
}
Fclose (FP );
Return 0;
}

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.