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 ...
随机推荐
- hdu 4038 2011成都赛区网络赛H 贪心 ***
贪心策略 1.使负数为偶数个,然后负数就不用管了 2.0变为1 3.1变为2 4.2变为3 5.若此时操作数剩1,则3+1,否则填个1+1,然后回到5
- Java8中的default方法
default方法 Java 8中引入了一个新的概念,叫做default方法,也可以称为Defender方法,或者虚拟扩展方法(Virtual extension methods). Default方 ...
- objective-c 遍历文件夹查看文件
#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ @autoreleasepool ...
- Windows7系统主题制作全程教程
jpg 改 rar
- 【Filter 不登陆无法访问】web项目中写一个过滤器实现用户不登陆,直接给链接,无法进入页面的功能
在web项目中写一个过滤器实现用户不登陆,直接给链接,无法进入页面,而重定向到登陆界面的功能. 项目是用springMVC+spring+hibernate实现 (和这个没有多大关系) 第一步: 首先 ...
- 安装 phpredis 扩展
/************************************************//********************* phpredis ***************** ...
- js-原型以及继承小案例
function human(name,tall){ this.name=name; this.tall=tall; this.toSleep=function(){ alert('no sleep' ...
- wpf,图片灰化处理
private BitmapSource ToGray(BitmapSource source) { FormatConvertedBitmap re = new FormatConvertedBit ...
- 模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels
题目传送门 /* 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0 很挫的判断四个方向是否OK */ #include <cs ...
- TFS安装与管理
整了几天TFS,把相关的一些配置与安装的要点简单记下,希望对大家有用.本篇主要是安装与配置上的内容,下一篇会介绍如何使用以及使用方面的相关心得体会. 本篇内容简要: 1. 安装部署 1.1. 流 ...