各种语言使用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 ...
随机推荐
- 上Google Adsense个人的一点体验
最近我想开通一个Google Adsense帐号,因为以前注册过一个Google帐号,所以我以为两个是可以共通的,因为很久没上Google帐号,我记不太清密码了,所以我先是登录了Google,登上去了 ...
- 与PHP5.3.5的战斗----记php5.3.5安装过程
与PHP5.3.5的战斗----记php5.3.5安装过程 摘自:http://blog.csdn.net/lgg201/article/details/6125189这篇文章写的很是不错,,,也是我 ...
- Java Internet
网络通信: 网络通信三要素: IP 协议 端口 TCP: 建立连接,发送速度慢 三次握手协议 UDP: 不需要建立连接,发送速度快 安全性低 a) 使用UDP实现数据的发送 1 创建Socket端点实 ...
- C++多线程同步之Mutex(互斥量)
原文链接: http://blog.csdn.net/olansefengye1/article/details/53086141 一.互斥量Mutex同步多线程 1.Win32平台 相关函数和头文件 ...
- Ubuntu下mysql的卸载重装
注:该方法是彻底删除ubuntu下面的文件,然后重新安装,更新root密码,所以mysql原数据会被删掉,所以一定一定要记得备份!!!!!!!! 转自:http://blog.csdn.net/chu ...
- 浅谈forword和sendRedirect
最近项目中全部用ajax请求数据,导致在做登录过滤器时不能重定向,然后仔细翻了翻Forward和sendRedirect,以下内容收集自百度: 1. forward (服务器端作的重定向) 服务器往c ...
- Spring MVC 学习笔记1 - First Helloworld by Eclipse【& - java web 开发Tips集锦】
Spring MVC 学习笔记1 - First Helloworld by Eclipse reference:http://www.gontu.org 1. 下载 Spring freamwork ...
- UVA-575-水题-模拟
题意: 按照这个公式模拟 10120skew = 1×(25 −1)+0×(24 −1)+1×(23 −1)+2×(22 −1)+0×(21 −1) = 31+0+7+6+0 = 44. #inclu ...
- 红帽配置Centos仓库[红帽Redhat7替换Centos7网络源]
1.卸载红帽yum源 rpm -e $(rpm -qa|grep yum) --nodeps 2.删除所有repo相关文件 rm -rf /etc/yum.conf rm -rf /etc/yum.r ...
- Openstack虚机实例状态错误手工恢复vm_state:error
Openstack虚机实例状态错误手工恢复vm_state:error 1.找到状态为出错状态的VM.在数据库里面表现Status为ERROR而非ACTIVE. 2.找到出错状态VM的UUID. 3. ...