HttpWebRequest Post callback
public void GetValueFromRequest(string postData)
{
var request = (HttpWebRequest) WebRequest.CreateHttp("http://login.test.geoop.com/oauth2/token"); byte[] requestBytes =
Encoding.UTF8.GetBytes(
postData); request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = requestBytes.Length; request.BeginGetRequestStream(GetRequestStreamCallback, request);
} private static void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
var request = (HttpWebRequest) asynchronousResult.AsyncState; // End the operation
var postStream = request.EndGetRequestStream(asynchronousResult); var postData = "grant_type=password&username=geooplive&password=geooppass&client_id=app4&scope=default"; // Convert the string into a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // Write to the request stream.
postStream.Write(byteArray, 0, postData.Length);
postStream.Close(); // Start the asynchronous operation to get the response
request.BeginGetResponse(GetResponseCallback, request);
} private static void GetResponseCallback(IAsyncResult asynchronousResult)
{
var request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response = null; // End the operation
try
{
response = (HttpWebResponse) request.EndGetResponse(asynchronousResult);
}
catch (WebException ex)
{
if (ex.Response != null)
{ }
} if (response.StatusCode == HttpStatusCode.Accepted)
{
Debug.WriteLine(response.ToString());
}
var streamResponse = response.GetResponseStream();
var streamRead = new StreamReader(streamResponse);
var responseString = streamRead.ReadToEnd();
Console.WriteLine(responseString);
// Close the stream object
streamResponse.Close();
streamRead.Close(); // Release the HttpWebResponse
response.Close();
}
HttpWebRequest Post callback的更多相关文章
- HttpWebRequest 模拟登录响应点击事件(分享自己用的HttpHelper类)
平时也经常采集网站数据,也做模拟登录,但一般都是html控件POST到页面登录:还没有遇到用户服务器控件button按钮点击事件登录的,今天像往常一样POST传递参数,但怎么都能登录不了:最后发现还有 ...
- HttpWebRequest BeginGetResponse EndGetResponse
private void Button_Click_4(object sender, RoutedEventArgs e) { HttpWebRequest request = HttpWebRequ ...
- 一个比较完善的httpWebRequest 封装,适合网络爬取及暴力破解
大家在模拟http请求的时候,对保持长连接及cookies,http头部信息等了解的不是那么深入.在各种网络请求过程中,发送N种问题. 可能问题如下: 1)登录成功后session保持 2)保证所有c ...
- Http异步发送之HttpWebRequest的BeginGetResponse
关于http异步发送,一开始我的做法都是用thread或者task去完成的:后来发现HttpWebRequest本身就提供一个异步的方法. 总感觉.Net自己提供的异步方法可能要优于我们自己用线程去实 ...
- HttpWebRequest - Asynchronous Programming Model/Task.Factory.FromAsyc
Posted by Shiv Kumar on 23rd February, 2011 The Asynchronous Programming Model (or APM) has been aro ...
- HttpWebRequest、HttpWebResponse、HttpClient、WebClient等http网络访问类的使用示例汇总
工作中长期需要用到通过HTTP调用API以及文件上传下载,积累了不少经验,现在将各种不同方式进行一个汇总. 首先是HttpWebRequest: /// <summary> /// 向服务 ...
- C# -- HttpWebRequest 和 HttpWebResponse 的使用 C#编写扫雷游戏 使用IIS调试ASP.NET网站程序 WCF入门教程 ASP.Net Core开发(踩坑)指南 ASP.Net Core Razor+AdminLTE 小试牛刀 webservice创建、部署和调用 .net接收post请求并把数据转为字典格式
C# -- HttpWebRequest 和 HttpWebResponse 的使用 C# -- HttpWebRequest 和 HttpWebResponse 的使用 结合使用HttpWebReq ...
- 记Outlook插件与Web页面交互的各种坑 (含c# HttpWebRequest 连接https 的完美解决方法)
1) 方案一, 使用Web Service 基础功能没问题, 只是在连接https (ssh) 网站时, 需要针对https进行开发 (即http 和https 生成两套接口, 不太容易统一 ). ...
- HttpWebRequest 以及WebRequest的使用
1.WebRequest的发送数据以及接收数据 class Program { static void Main(string[] args) { //创建一个实例并发送请求 HttpWebReque ...
随机推荐
- 获取当前IP地址,跳转到对应城市网站。
index.php文件 1,通过获取当前IP地址, 2,调用新浪AIP,获取到当前城市. 3,将中文转换为拼音后跳转. <?php include './pinyin.php'; //获取当前i ...
- Linux下配置OpenCV1.0环境
自己一直嚷嚷着打算学学图像识别,识别个简单的,车牌号,验证码之类的,之前查过资料,OpenCV可以实现.昨天花了一个下午终于配置好环境了,今天写下总结. OpenCV这一名称包含了Open和Compu ...
- 用C#基于WCF创建TCP的Service供Client端调用
本文将详细讲解用C#基于WCF创建TCP的Service供Client端调用的详细过程 1):首先创建一个Windows Service的工程 2):生成的代码工程结构如下所示 3):我们将Servi ...
- Java学习笔记(三)——运算符
一.运算符: 1.分类: 2.java中的运算符 (1)其中,++在左,表示先加了再用,++在右,表示先用了再加. (2)% 用来求余数,也称为"取模运算符" 3.赋值运算符 4. ...
- sql2014 新建用户并登陆
EXEC master.dbo.sp_addlogin @loginame = N'testuser1', @passwd = '123456', @defdb = N'master', @defla ...
- poj 2115 Looooops
C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23637 Accepted: 6528 Descr ...
- HTTP基础09--web(1)
Web 应用 通过 Web 提供功能的 Web 应用 原本应用 HTTP 协议的 Web 的机制就是对客户端发来的请求,返回事前准备好的内容.可随着 Web 越来越普及,仅靠这样的做法已不足以应对所有 ...
- 启动windows的服务--《用delphi开发共享软件》-15.2桌面提示器
在dos 下用命令启动一个服务:NET START "Windows Desktop Reminder" 一下为用delphi启动服务: Function RunProcess(s ...
- 归并排序(Merge Sort)
归并排序是建立在归并操作上的一种有效的排序算法,该算法是采用分治法(Divide and Conquer)的一个非常典型的应用.将已有序的子序列合并,得到完全有序的序列:即先使每个子序列有序,再使子序 ...
- 简单的jQuery扩展函数-让函数缓冲执行
$.fn.retarder = function(delay, method) { var node = this; if (node.length) { if (node[0]._timer_) c ...