各种语言使用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 ...
随机推荐
- java学习——构造类之3!+5!=126
package my_project; import java.util.Scanner; public class my_first_class { public static void main( ...
- Linux下查看某个进程占用的CPU、内存
1.用top命令指定固定的PID top -p 10997 查询指定进程的PID ps -ef | grep zookeeper jim 10997 1959 0 12月14 pts/2 00:00: ...
- 在Linux 系统 Latex安装 使用入门教程
来源: http://blog.chinaunix.net/u/25605/showart_2100398.html 入门介绍好文:TeX.LaTeX.TeXLive 小结 笔记详情:http://v ...
- linux shell 命令常用快捷键
下面是一些shell的常用快捷键,快捷键玩熟悉了在一定程度上是可以提高工作效率滴… Ctrl + a 切换到命令行开始 Ctrl + e 切换到命令行末尾 Ctrl + l 清除屏幕内容 Ctrl + ...
- Fragment之介绍(转)
http://www.cnblogs.com/plokmju/p/3239265.html 前言 开门见山开篇名义,本篇博客将讲解一下Android中Fragment的内容,必要的地方会提供相应的演示 ...
- RBAC相关的配置
一.什么是RBAC 基于角色的访问控制(Role-Based Access Control)作为传统访问控制(自主访问,强制访问)的有前景的代替受到广泛的关注. 在RBAC中,权限与角色相关联,用户通 ...
- MongoDB对Javascript的支持
在项目中MongoDB的Map-Reduce功能做了许多统计任务,在重构代码的时候修改了_id对象里面的属性字段名称,当用db.collection.update({$rename:{"_i ...
- python并发编程之多进程理论部分
原文连接:http://www.cnblogs.com/linhaifeng/articles/7430066.html#_label4 一 什么是进程 进程:正在进行的一个过程或者说一个任务.而负责 ...
- python入门-列表
列表使用[]来标识 列表和PHP中的数组类似 包括使用和访问方式都是类似 可以用下标索引的方式直接访问 来几个例子,这样看起来才舒服 names = ['baker','pitty','david', ...
- TortoiseGit上传项目到GitHub
1. 简介 gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub. 2. 准备 2.1 安装git:https://git-scm.c ...