C#代码模拟http发送get和post请求
- private string HttpPost(string Url, string postDataStr)
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
- request.Method = "POST";
- request.ContentType = "application/x-www-form-urlencoded";
- request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
- request.CookieContainer = cookie;
- Stream myRequestStream = request.GetRequestStream();
- StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
- myStreamWriter.Write(postDataStr);
- myStreamWriter.Close();
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- response.Cookies = cookie.GetCookies(response.ResponseUri);
- Stream myResponseStream = response.GetResponseStream();
- StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
- string retString = myStreamReader.ReadToEnd();
- myStreamReader.Close();
- myResponseStream.Close();
- return retString;
- }
- public string HttpGet(string Url, string postDataStr)
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
- request.Method = "GET";
- request.ContentType = "text/html;charset=UTF-8";
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- Stream myResponseStream = response.GetResponseStream();
- StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
- string retString = myStreamReader.ReadToEnd();
- myStreamReader.Close();
- myResponseStream.Close();
- return retString;
- }
C#代码模拟http发送get和post请求的更多相关文章
- 使用java程序模拟页面发送http的post请求
在web应用程序中,一般都是通过页面发送http的post请求,但也可以使用java程序来模拟页面发送请求,代码如下: import java.io.BufferedReader; import ja ...
- C#模拟http 发送post或get请求
/// <summary> /// 模拟HTTP提交表单并获取返回数据 /// POST /// </summary> /// <param name="Url ...
- 【转】C#模拟http 发送post或get请求
原文地址:http://www.cnblogs.com/xssxss/archive/2012/07/03/2574554.html 模拟POST Json public static string ...
- 使用appium模拟用户发送短信
一段简单粗糙的代码.主要是实现的功能是模拟用户发送短信的功能. python版本3.5.2 appium版本1.4.16.1 from appium import webdriver desired_ ...
- C#模拟httpwebrequest请求_向服务器模拟cookie发送
使用C#代码模拟web请求,是一种常用的方法,以前没专门整理过,这里暂时贴上自己整理的完整代码,以后再做梳理: public class MyRequest { #region 辅助方法 public ...
- php使用curl模拟多线程发送请求
每个PHP文件的执行是单线程的,但是php本身也可以用一些别的技术实现多线程并发比如用php-fpm进程,这里用curl模拟多线程发送请求.php的curl多线程是通过不断调用curl_multi_e ...
- 使用HttpClient配置代理服务器模拟浏览器发送请求调用接口测试
在调用公司的某个接口时,直接通过浏览器配置代理服务器可以请求到如下数据: 请求url地址:http://wwwnei.xuebusi.com/rd-interface/getsales.jsp?cid ...
- php模拟发送GET和POST请求
php分别模拟发送GET和POST请求,非常实用的额,也可作PHP CURL入门级的理解教材的,示例代码如下: <?php /* ** php分别模拟发送GET与POST请求 ** */ fun ...
- js_html_input中autocomplete="off"在chrom中失效的解决办法 使用JS模拟锚点跳转 js如何获取url参数 C#模拟httpwebrequest请求_向服务器模拟cookie发送 实习期学到的技术(一) LinqPad的变量比较功能 ASP.NET EF 使用LinqPad 快速学习Linq
js_html_input中autocomplete="off"在chrom中失效的解决办法 分享网上的2种办法: 1-可以在不需要默认填写的input框中设置 autocompl ...
随机推荐
- 使用sphinx索引mysql数据
数据库表如下 mysql> select * from tb_account; +----+-------+------+ | id | name | age | +----+-------+- ...
- cmd命令 拷贝某文件夹及其子文件夹文件到其它文件夹
@ECHO OFF cd/d %H:\FileLoc\CNET&cd.. ::echo 拷贝"%H:\FileLoc\CNET"中文件到"H:\FileLocTe ...
- IOS开发环境更换后重新制作Provisioning Profile证书详解
新换了台Macbook,又折腾了一遍Provisioning Profile证书,苹果的证书繁锁复杂,每次制作都相当麻烦,而且Provisioning Profile证书是与设备绑定的,所以更换开发环 ...
- Android Json生成及解析实例
JSON的定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据 ...
- hdu-5082
题意非常easy,就是给出父母的名字,然后依据父母的名字来给孩纸取名字! 能够将此题简化为: 孩纸的名字=父亲的frist name+字符串(_small_)+母亲额frist name; 然后将孩纸 ...
- <转>ASP.NET学习笔记之MVC 3 数据验证 Model Validation 详解
MVC 3 数据验证 Model Validation 详解 再附加一些比较好的验证详解:(以下均为引用) 1.asp.net mvc3 的数据验证(一) - zhangkai2237 - 博客园 ...
- DataTable 修改列名 删除列 调整列顺序
DataTable myDt =dt;//删除列myDt.Columns.Remove("minArea");myDt.Columns.Remove("maxArea&q ...
- linux 分割文件
import os import sysimport subprocess if len(sys.argv)<3 : print 'usage: filenum filename' file_n ...
- apktool 反翻译错误
-出现 UndefinedResObject Exception : 这是因为被反编译的apk中有当前的framework不支持的属性:解决方式如下: 1.删除C:\Users\Administrat ...
- Android 汉字转拼音之工具篇
/* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Versi ...