123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- // WINHTTPS.cpp : 定义控制台应用程序的入口点。
- //
- #include "stdafx.h"
- #include "HTTPDef.h"
- #include "HTTPHelper.h"
- void test_get()
- {
- HTTPRESULT result;
- HTTPHelper hhelper;
- hhelper.SetMethod(L"POST");
- // 用来指定当前的请求/回复中的,是否使用缓存机制
- //hhelper.AddRequestHeaders(L"Cache-Control", L"no-cache");
- // 发送请求的客户端的类型
- hhelper.AddRequestHeaders(L"User-Agent", L"Moka_Factory/1.0.01");
- // 可接受的字符集;
- //hhelper.AddRequestHeaders(L"Accept-Charset", L"UTF-8");
- //可接受的响应内容类型
- //hhelper.AddRequestHeaders(L"Accept", L"*/*");
- // 可接受的响应内容的编码方式
- //hhelper.AddRequestHeaders(L"Accept-Encoding", L"gzip, deflate, br");
- // 可接受的响应内容语言列表
- //hhelper.AddRequestHeaders(L"Accept-Language", L"?");
- // 客户端(浏览器)想要优先使用的连接类型
- hhelper.AddRequestHeaders(L"Connection", L"keep-alive");
- // 请求的报文格式
- //hhelper.AddRequestHeaders(L"Content-type", L"?");
- //hhelper.SetUrl(L"http://huizhou.idmanage.qhmoka.com/IDManage/getid.do?devicetype=SCBC_RT2851M&sn=DGG75095762111001764&order=DGG7509576");
- hhelper.SetUrl(L"http://huizhou.idmanage.qhmoka.com/IDManage/getid.do");
- hhelper.AddQueryParams(L"devicetype", L"SCBC_RT2851M");
- hhelper.AddQueryParams(L"sn", L"DGG75095762111001764");
- hhelper.AddQueryParams(L"order", L"DGG7509576");
- hhelper.GetHtml(result);
- wprintf(L"ResponseHeader=%s\r\n",result.m_strHeader.c_str());
- wprintf(L"StatusCode=%ld\r\n", result.m_dwStatusCode);
- if (result.m_dwStatusCode == 200)
- printf("ResponseData=%s\r\n",result.m_strResponseData.c_str());
- system("pause");
- }
- void test_getmessageV2()
- {
- HTTPRESULT res;
- HTTPHelper hhelper;
- hhelper.SetMethod(L"POST");
- #pragma region 造成Post时返回分块编码的原因是:Accept-Encoding中gzip造成数据压缩传输了.
- // 禁用此头后,接口数据返回正常;
- // hhelper.AddRequestHeaders(L"Accept-Encoding", L"gzip, deflate, br");
- #pragma endregion
- hhelper.SetUrl(L"http://test.scbc.qhmoka.com/scbc-server/clientType/getMessage.do");
- hhelper.AddBodyRawData("{\"bid\":\"TEST_WJF\",\"mac\":\"04-D4-C4-EE-6B-CD\"}", L"application/json;charset=utf-8");
- hhelper.GetHtml(res);
- wprintf(L"ResponseHeader=%s\r\n",res.m_strHeader.c_str());
- wprintf(L"StatusCode=%ld\r\n", res.m_dwStatusCode);
- if (res.m_dwStatusCode == 200)
- printf("ResponseData=%s\r\n",res.m_strResponseData.c_str());
- system("pause");
- int a = 0;
- }
- void test_getkey()
- {
- HTTPRESULT res;
- HTTPHelper http;
- http.SetMethod(L"POST");
- http.SetUrl(L"http://test.idmanage.qhmoka.com/IDManage/v2/bind/order");
- http.AddBodyRawData("{\"orderNum\":\"TEST_WJF\",\"sn\":\"SN0321-test9999\",\"psn\":\"20220321APSN9999\",\"orderCode\":\"BBB\",\"skipKey\": []}", L"application/json;charset=utf8");
- http.GetHtml(res);
- wprintf(L"ResponseHeader=%s\r\n",res.m_strHeader.c_str());
- wprintf(L"StatusCode=%ld\r\n", res.m_dwStatusCode);
- if (res.m_dwStatusCode == 200)
- printf("ResponseData=%s\r\n",res.m_strResponseData.c_str());
- system("pause");
- int a = 0;
- }
- void test_download()
- {
- //http://szidmanage.file.qhmoka.com/JsonFile/SanHua/20220718091143128.json
- //https://bbs.pediy.com/attach-download-197174-8975e845ab91d7d04fee9d527f739f6d@v9DMStXlWsHI08Zl2C_2FIqg_3D_3D.htm
- HTTPRESULT result;
- HTTPHelper hhelper;
- hhelper.SetMethod(L"GET");
- hhelper.AddRequestHeaders(L"Cache-Control", L"no-cache");
- hhelper.AddRequestHeaders(L"User-Agent", L"Moka_Factory/1.0.01");
- hhelper.AddRequestHeaders(L"Accept", L"*/*");
- //hhelper.AddRequestHeaders(L"Accept-Encoding", L"gzip, deflate, br");
- //hhelper.AddRequestHeaders(L"Connection", L"keep-alive");//持续连接,会产生分块编码(Transfer-Encoding: chunked)
- hhelper.AddRequestHeaders(L"Connection", L"close"); //关闭,也一样会产生会分块编码(Transfer-Encoding: chunked)
- //content-encoding
- //hhelper.AddRequestHeaders(L"Content-Encoding", L"UTF-8"); // POST时才需要用到;
- //hhelper.AddRequestHeaders(L"Content-Type", L"application/json;charset=utf8"); // POST时才需要用到;
- //hhelper.AddRequestHeaders(L"Content-Length", L"755"); // POST时才需要用到
- //hhelper.SetUrl(L"http://szidmanage.file.qhmoka.com/JsonFile/SanHua/20220718091143128.json");
- hhelper.SetUrl(L"https://codown.youdao.com/cidian/static/9.0/20220608/YoudaoDictSetup.exe");
- hhelper.SetTimeout(0,60000,60000,120000);
- //hhelper.SetPostData(L"{\"bid\":\"TEST_WJF\",\"mac\":\"04-D4-C4-EE-6B-CD\"}");
- //hhelper.AddBodyRawData(L"{\"bid\":\"TEST_WJF\",\"mac\":\"04-D4-C4-EE-6B-CD\"}", L"application/json");
- hhelper.GetHtml(result);
- wprintf(L"ResponseHeader=%s\r\n",result.m_strHeader.c_str());
- wprintf(L"StatusCode=%ld\r\n", result.m_dwStatusCode);
- if (result.m_dwStatusCode == 200)
- printf("ResponseData=%s\r\n",result.m_strResponseData.c_str());
- system("pause");
- }
- void test_login()
- {
- HTTPRESULT res;
- HTTPHelper http;
- http.SetMethod(L"POST");
- http.SetUrl(L"http://test.scbc.qhmoka.com/scbc-server/login.do");
- http.AddBodyRawData("{\"account\":\"SanHua\",\"password\":\"admin\",\"mac\":\"A0-00-00-00-00-0A\"}", L"application/json;charset=utf-8");
-
- http.GetHtml(res);
- wprintf(L"ResponseHeader=%s\r\n",res.m_strHeader.c_str());
- wprintf(L"StatusCode=%ld\r\n", res.m_dwStatusCode);
- if (res.m_dwStatusCode == 200)
- printf("ResponseData=%s\r\n",res.m_strResponseData.c_str());
- system("pause");
- }
- void test_updateCheck()
- {
- HTTPRESULT res;
- HTTPHelper http;
- http.SetMethod(L"POST");
- //http.SetUrl(L"https://test.uc.qhmoka.com/ota-services/upmp/upgradeIncrForTool");
- http.SetUrl(L"https://cn.ota.qhmoka.com/ota-services/upmp/upgradeIncrForTool");
- http.AddBodyRawData("{\"appid\":\"SCBC_Factory_Tools\",\"devicemodel\":\"SCBC_Factory_Tools\",\"dnum\":\"111\",\"ver\":\"3.0.6.4\",\"type\":\"pc\"}", L"application/json;charset=utf-8");
-
- http.GetHtml(res);
- wprintf(L"ResponseHeader=%s\r\n",res.m_strHeader.c_str());
- wprintf(L"StatusCode=%ld\r\n", res.m_dwStatusCode);
- if (res.m_dwStatusCode == 200)
- printf("ResponseData=%s\r\n",res.m_strResponseData.c_str());
- system("pause");
- }
- void test_getmssage()
- {
- HTTPRESULT res;
- HTTPHelper http;
- http.SetMethod(L"POST");
- http.SetUrl(L"https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do");
- http.AddBodyRawData("{\"clientType\":\"\",\"version\":\"\",\"bid\":\"IDE963353D\",\"mac\":\"94-DE-80-AA-CE-C9\"}", L"application/json;charset=utf-8");
- http.GetHtml(res);
- wprintf(L"ResponseHeader=%s\r\n",res.m_strHeader.c_str());
- wprintf(L"StatusCode=%ld\r\n", res.m_dwStatusCode);
- if (res.m_dwStatusCode == 200)
- printf("ResponseData=%s\r\n",res.m_strResponseData.c_str());
- system("pause");
- }
- void test()
- {
- test_login();
- test_updateCheck();
- test_getmssage();
- test_getmessageV2();
- test_getkey();
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- test();
- return 0;
- }
|