WINHTTPS.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // WINHTTPS.cpp : 定义控制台应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include "HTTPDef.h"
  5. #include "HTTPHelper.h"
  6. void test_get()
  7. {
  8. HTTPRESULT result;
  9. HTTPHelper hhelper;
  10. hhelper.SetMethod(L"POST");
  11. // 用来指定当前的请求/回复中的,是否使用缓存机制
  12. //hhelper.AddRequestHeaders(L"Cache-Control", L"no-cache");
  13. // 发送请求的客户端的类型
  14. hhelper.AddRequestHeaders(L"User-Agent", L"Moka_Factory/1.0.01");
  15. // 可接受的字符集;
  16. //hhelper.AddRequestHeaders(L"Accept-Charset", L"UTF-8");
  17. //可接受的响应内容类型
  18. //hhelper.AddRequestHeaders(L"Accept", L"*/*");
  19. // 可接受的响应内容的编码方式
  20. //hhelper.AddRequestHeaders(L"Accept-Encoding", L"gzip, deflate, br");
  21. // 可接受的响应内容语言列表
  22. //hhelper.AddRequestHeaders(L"Accept-Language", L"?");
  23. // 客户端(浏览器)想要优先使用的连接类型
  24. hhelper.AddRequestHeaders(L"Connection", L"keep-alive");
  25. // 请求的报文格式
  26. //hhelper.AddRequestHeaders(L"Content-type", L"?");
  27. //hhelper.SetUrl(L"http://huizhou.idmanage.qhmoka.com/IDManage/getid.do?devicetype=SCBC_RT2851M&sn=DGG75095762111001764&order=DGG7509576");
  28. hhelper.SetUrl(L"http://huizhou.idmanage.qhmoka.com/IDManage/getid.do");
  29. hhelper.AddQueryParams(L"devicetype", L"SCBC_RT2851M");
  30. hhelper.AddQueryParams(L"sn", L"DGG75095762111001764");
  31. hhelper.AddQueryParams(L"order", L"DGG7509576");
  32. hhelper.GetHtml(result);
  33. wprintf(L"ResponseHeader=%s\r\n",result.m_strHeader.c_str());
  34. wprintf(L"StatusCode=%ld\r\n", result.m_dwStatusCode);
  35. if (result.m_dwStatusCode == 200)
  36. printf("ResponseData=%s\r\n",result.m_strResponseData.c_str());
  37. system("pause");
  38. }
  39. void test_getmessageV2()
  40. {
  41. HTTPRESULT res;
  42. HTTPHelper hhelper;
  43. hhelper.SetMethod(L"POST");
  44. #pragma region 造成Post时返回分块编码的原因是:Accept-Encoding中gzip造成数据压缩传输了.
  45. // 禁用此头后,接口数据返回正常;
  46. // hhelper.AddRequestHeaders(L"Accept-Encoding", L"gzip, deflate, br");
  47. #pragma endregion
  48. hhelper.SetUrl(L"http://test.scbc.qhmoka.com/scbc-server/clientType/getMessage.do");
  49. hhelper.AddBodyRawData("{\"bid\":\"TEST_WJF\",\"mac\":\"04-D4-C4-EE-6B-CD\"}", L"application/json;charset=utf-8");
  50. hhelper.GetHtml(res);
  51. wprintf(L"ResponseHeader=%s\r\n",res.m_strHeader.c_str());
  52. wprintf(L"StatusCode=%ld\r\n", res.m_dwStatusCode);
  53. if (res.m_dwStatusCode == 200)
  54. printf("ResponseData=%s\r\n",res.m_strResponseData.c_str());
  55. system("pause");
  56. int a = 0;
  57. }
  58. void test_getkey()
  59. {
  60. HTTPRESULT res;
  61. HTTPHelper http;
  62. http.SetMethod(L"POST");
  63. http.SetUrl(L"http://test.idmanage.qhmoka.com/IDManage/v2/bind/order");
  64. http.AddBodyRawData("{\"orderNum\":\"TEST_WJF\",\"sn\":\"SN0321-test9999\",\"psn\":\"20220321APSN9999\",\"orderCode\":\"BBB\",\"skipKey\": []}", L"application/json;charset=utf8");
  65. http.GetHtml(res);
  66. wprintf(L"ResponseHeader=%s\r\n",res.m_strHeader.c_str());
  67. wprintf(L"StatusCode=%ld\r\n", res.m_dwStatusCode);
  68. if (res.m_dwStatusCode == 200)
  69. printf("ResponseData=%s\r\n",res.m_strResponseData.c_str());
  70. system("pause");
  71. int a = 0;
  72. }
  73. void test_download()
  74. {
  75. //http://szidmanage.file.qhmoka.com/JsonFile/SanHua/20220718091143128.json
  76. //https://bbs.pediy.com/attach-download-197174-8975e845ab91d7d04fee9d527f739f6d@v9DMStXlWsHI08Zl2C_2FIqg_3D_3D.htm
  77. HTTPRESULT result;
  78. HTTPHelper hhelper;
  79. hhelper.SetMethod(L"GET");
  80. hhelper.AddRequestHeaders(L"Cache-Control", L"no-cache");
  81. hhelper.AddRequestHeaders(L"User-Agent", L"Moka_Factory/1.0.01");
  82. hhelper.AddRequestHeaders(L"Accept", L"*/*");
  83. //hhelper.AddRequestHeaders(L"Accept-Encoding", L"gzip, deflate, br");
  84. //hhelper.AddRequestHeaders(L"Connection", L"keep-alive");//持续连接,会产生分块编码(Transfer-Encoding: chunked)
  85. hhelper.AddRequestHeaders(L"Connection", L"close"); //关闭,也一样会产生会分块编码(Transfer-Encoding: chunked)
  86. //content-encoding
  87. //hhelper.AddRequestHeaders(L"Content-Encoding", L"UTF-8"); // POST时才需要用到;
  88. //hhelper.AddRequestHeaders(L"Content-Type", L"application/json;charset=utf8"); // POST时才需要用到;
  89. //hhelper.AddRequestHeaders(L"Content-Length", L"755"); // POST时才需要用到
  90. //hhelper.SetUrl(L"http://szidmanage.file.qhmoka.com/JsonFile/SanHua/20220718091143128.json");
  91. hhelper.SetUrl(L"https://codown.youdao.com/cidian/static/9.0/20220608/YoudaoDictSetup.exe");
  92. hhelper.SetTimeout(0,60000,60000,120000);
  93. //hhelper.SetPostData(L"{\"bid\":\"TEST_WJF\",\"mac\":\"04-D4-C4-EE-6B-CD\"}");
  94. //hhelper.AddBodyRawData(L"{\"bid\":\"TEST_WJF\",\"mac\":\"04-D4-C4-EE-6B-CD\"}", L"application/json");
  95. hhelper.GetHtml(result);
  96. wprintf(L"ResponseHeader=%s\r\n",result.m_strHeader.c_str());
  97. wprintf(L"StatusCode=%ld\r\n", result.m_dwStatusCode);
  98. if (result.m_dwStatusCode == 200)
  99. printf("ResponseData=%s\r\n",result.m_strResponseData.c_str());
  100. system("pause");
  101. }
  102. void test_login()
  103. {
  104. HTTPRESULT res;
  105. HTTPHelper http;
  106. http.SetMethod(L"POST");
  107. http.SetUrl(L"http://test.scbc.qhmoka.com/scbc-server/login.do");
  108. http.AddBodyRawData("{\"account\":\"SanHua\",\"password\":\"admin\",\"mac\":\"A0-00-00-00-00-0A\"}", L"application/json;charset=utf-8");
  109. http.GetHtml(res);
  110. wprintf(L"ResponseHeader=%s\r\n",res.m_strHeader.c_str());
  111. wprintf(L"StatusCode=%ld\r\n", res.m_dwStatusCode);
  112. if (res.m_dwStatusCode == 200)
  113. printf("ResponseData=%s\r\n",res.m_strResponseData.c_str());
  114. system("pause");
  115. }
  116. void test_updateCheck()
  117. {
  118. HTTPRESULT res;
  119. HTTPHelper http;
  120. http.SetMethod(L"POST");
  121. //http.SetUrl(L"https://test.uc.qhmoka.com/ota-services/upmp/upgradeIncrForTool");
  122. http.SetUrl(L"https://cn.ota.qhmoka.com/ota-services/upmp/upgradeIncrForTool");
  123. 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");
  124. http.GetHtml(res);
  125. wprintf(L"ResponseHeader=%s\r\n",res.m_strHeader.c_str());
  126. wprintf(L"StatusCode=%ld\r\n", res.m_dwStatusCode);
  127. if (res.m_dwStatusCode == 200)
  128. printf("ResponseData=%s\r\n",res.m_strResponseData.c_str());
  129. system("pause");
  130. }
  131. void test_getmssage()
  132. {
  133. HTTPRESULT res;
  134. HTTPHelper http;
  135. http.SetMethod(L"POST");
  136. http.SetUrl(L"https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do");
  137. http.AddBodyRawData("{\"clientType\":\"\",\"version\":\"\",\"bid\":\"IDE963353D\",\"mac\":\"94-DE-80-AA-CE-C9\"}", L"application/json;charset=utf-8");
  138. http.GetHtml(res);
  139. wprintf(L"ResponseHeader=%s\r\n",res.m_strHeader.c_str());
  140. wprintf(L"StatusCode=%ld\r\n", res.m_dwStatusCode);
  141. if (res.m_dwStatusCode == 200)
  142. printf("ResponseData=%s\r\n",res.m_strResponseData.c_str());
  143. system("pause");
  144. }
  145. void test()
  146. {
  147. test_login();
  148. test_updateCheck();
  149. test_getmssage();
  150. test_getmessageV2();
  151. test_getkey();
  152. }
  153. int _tmain(int argc, _TCHAR* argv[])
  154. {
  155. test();
  156. return 0;
  157. }