各种语言使用HTTP Request
String requestContent = "{"id":"1","sort":"des","number":"9","startIndex":"1"}";
try {
StringEntity entity = new StringEntity(requestContent);
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json"); //set the request content type as JSON
httpPost.setEntity(entity);
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
httpResponse=httpClient.execute(httpPost);
#include "stdafx.h"
#include "windows.h"
#include <iostream>
#include <crtdbg.h>
#include <string>
#include <winhttp.h>
#pragma comment(lib, "winhttp")
using namespace std; void do_work(string strUrl);
int _tmain(int argc, _TCHAR* argv[])
{
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
do_work("https://albert.apple.com/WebObjects/ALUnbrick.woa/wa/deviceActivation?device=MacOS");
system("pause");
} void do_work(string strUrl)
{
DWORD dwSize = ;
DWORD dwDownloaded = ;
LPSTR pszOutBuffer;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
//get the proxy
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig = { };
if (!::WinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig))
{
// Call GetLastError for error information.
cout << "Error in getting proxy..." << endl;
}
WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions = { };
if(ieProxyConfig.fAutoDetect)
{
autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT;
autoProxyOptions.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A;
} // Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen(L"A WinHTTP Example Program/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, ); // Specify an HTTP server
if (hSession)
hConnect = WinHttpConnect(hSession, L"baidu.com",
INTERNET_DEFAULT_HTTP_PORT, ); // Create an HTTP Request handle.
if (hConnect)
hRequest = WinHttpOpenRequest(hConnect, L"GET",
L"", //requestStr
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
); // Send a Request.
if (hRequest)
bResults = WinHttpSendRequest(hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
, WINHTTP_NO_REQUEST_DATA, ,
, ); // End the request.
if (bResults)
bResults = WinHttpReceiveResponse(hRequest, NULL); // Continue to verify data until there is nothing left.
if (bResults)
{
do
{
// Verify available data.
dwSize = ;
if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
printf("Error %u in WinHttpQueryDataAvailable.\n",
GetLastError()); // Allocate space for the buffer.
pszOutBuffer = new char[dwSize+]; // Read the Data.
ZeroMemory(pszOutBuffer, dwSize+); if (!WinHttpReadData(hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded))
printf("Error %u in WinHttpReadData.\n", GetLastError());
else
printf("%s\n", pszOutBuffer); // Free the memory allocated to the buffer.
delete[] pszOutBuffer;
} while (dwSize > );
} // Report errors.
if (!bResults)
printf("Error %d has occurred.\n", GetLastError()); // Close open handles.
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);
}
各种语言使用HTTP Request的更多相关文章
- JSP 内置对象(request response session application out pageContext)
request对象 javax.servlet.http.HttpServletRequest接口的实例 request.setCharacterEncoding("utf-8" ...
- Asp.net mvc 小试牛刀一:多语言支持
最近因为项目需要又从UWP开发转到了Asp.net mvc 开发,由于也不是什么老手,所以就将项目常见的一些技术问题记录一下自己的解决方案. 第一个需求:用户可以自由切换界面显示语言. 解决方案一:界 ...
- Flask中request参数
首先要明确一件事,Request这是个对象,不管使用PHP还是python还是什么java语言,虽然request这个对象可能叫的名字不一样,(在其他语言中可能叫什么HttpRequest),但是原理 ...
- .NET资源文件实现多语言切换
1.创建对应的资源文件 lang.en.resx 英文 lang.resx 中文,默认 lang.zh-tw.resx 繁体 首先说明,这三个文件前面部分名称需要一样,只是 点 后面的语言代号 ...
- Struts2操作request、session和application对象
Struts 2提供了多种方式来访问上述的三种对象,归结起来,可以划分为两大类:与Servlet API解耦的访问方式和与Servlet API耦合的访问方式. 与Servlet API解耦的访问方式 ...
- go语言爬虫goquery和grequests的使用
/*下载工具*/ package main import ( "fmt" //go语言版本的jquery "github.com/PuerkitoBio/goquery& ...
- Request介绍及演示样例 PART1
Request在ServletAPI的规范连接地址http://blog.csdn.net/zghwaicsdn/article/details/51035146 HTTP简介 URL是浏览器寻找信息 ...
- 关于在JSP页面中为什么一定要用${pageContext.request.contextPath}来获取项目路径,而不能用${request.contextPath}?
这里的疑问在于pageContext和request都是JSP中的内置对象之一,为什么不直接用${request.contextPath}来获取项目路径? 出现这种疑问,其实是将JSP的内置对象和EL ...
- Web核心之Request对象
HTTP协议中Request请求部分格式 //请求行(这种是POST类型的请求) POST /HttpServleLogin.html HTTP/1.1 //请求头(User-Agent里有Firef ...
随机推荐
- 杂项:flex (adobe flex)
ylbtech-杂项:Flex (Adobe Flex) Flex指Adobe Flex,基于其专有的Macromedia Flash平台,它是涵盖了支持RIA(Rich Internet Appli ...
- HTML5: input:file上传类型控制
ylbtech-HTML5: input:file上传类型控制 1. 一.input:file 属性返回顶部 一.input:file属性 属性值有以下几个比较常用: accept:表示可以选择的 ...
- JVM的DirectMemory设置
转载http://blog.csdn.net/zshake/article/details/46785469 几台服务器的JVM占用内存总是持续增长,大大超过-Xmx设定的值,服务器物理内存几乎被耗尽 ...
- 在Linux 系统 Latex安装 使用入门教程
来源: http://blog.chinaunix.net/u/25605/showart_2100398.html 入门介绍好文:TeX.LaTeX.TeXLive 小结 笔记详情:http://v ...
- 补充 3:Golang 一些特性
1 丰富的内置类型 2 函数多返回值 3 Go的错误处理 : Go语言引入了3个关键字用于标准的错误处理流程,这3个关键字分别为defer. panic和 recover 4 在Go语言中,所有的 ...
- c++并发编程实战 笔记
http://blog.csdn.net/u010087886/article/category/5884745
- python入门第0篇 Windows下python的安装及pip安装和使用
知识内容: 1. python2和python3安装 2. pip安装及pip命令使用 注:安装python3就可以了,python2除非项目开发需要否则不用安装,目前学习python就使用pytho ...
- UVA133
减少领取救济金排队的长度是一个严重的问题,The New National Green Labour RhinocerosParty (这个党派)依据如下规则.每天来领取救济金的人排成一个大圆环.任选 ...
- Linux运维面试贩卖思路如下
1.自我介绍 2.技术介绍 3.上家公司情况介绍.多少人的团队.运维多少人.多少设备.公司什么业务.访问量多少.并发多少.架构多大,然后介绍公司架构.CDN->负载均衡->web-> ...
- ldap复制
1.使用yum命令安装openldap,openldap-servers,openldap-clients $ yum install openldap $ yum install openldap- ...