首页 技术 正文
技术 2022年11月8日
0 收藏 853 点赞 1,568 浏览 2576 个字
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.IO;namespace Sample2
{
class Program
{
static void Main(string[] args)
{
try
{
//data
string cookieStr = "51fd9f14fa7561b5";
string postData = string.Format("userid={0}&password={1}", "guest", "");
byte[] data = Encoding.UTF8.GetBytes(postData); // Prepare web request...
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.xxx.com");
request.Method = "POST";
//request.Referer = "https://www.xxx.com";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36";
//request.Host = "www.xxx.com";
request.Headers.Add("Cookie", cookieStr);
request.ContentLength = data.Length;
Stream newStream = request.GetRequestStream(); // Send the data.
newStream.Write(data, , data.Length);
newStream.Close(); // Get response
HttpWebResponse myResponse = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
Console.WriteLine(content);
Console.ReadLine();
}
catch (Exception)
{
throw;
}
}
}
}
/// <summary>
/// 调用短信接口发送短信,需配合模板
/// </summary>
/// <param name="userName">接口用户名</param>
/// <param name="userPwd">接口密码</param>
/// <param name="mobile">发送手机号码</param>
/// <param name="content">发送内容</param>
/// <returns> 返回值大于0,发送成功,系统生成的任务id或自定义的任务id</returns>
public static string PostSms(string userName, string userPwd, string mobile, string content)
{
string srcString = "-999";
try
{
string postString = string.Format("username={0}&password={1}&mobile={2}&content={3}", userName, MD5(userName + MD5(userPwd)), mobile, content);
byte[] postData = Encoding.UTF8.GetBytes(postString);//编码,尤其是汉字,事先要看下抓取网页的编码方式
string url = "http://xxx/smsSend.do";//地址
WebClient webClient = new WebClient();
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//采取POST方式必须加的header,如果改为GET方式的话就去掉这句话即可
byte[] responseData = webClient.UploadData(url, "POST", postData);//得到返回字符流
srcString = Encoding.UTF8.GetString(responseData);//解码
}
catch { }
return srcString;
}
    class Program
{
static void Main(string[] args)
{
var str = DownloadStringAsync(new Uri("http://www.baidu.com"));
Console.WriteLine(str.Result);
Console.ReadLine();
} static async Task<string> DownloadStringAsync(Uri uri)
{
//WebClient 不支持超时设定
//而HttpWebRequst则允许你设置请求头或者对内容需要更多的控制
var webClient = new WebClient();
webClient.Encoding = System.Text.Encoding.UTF8;
var result = await webClient.DownloadStringTaskAsync(uri);
return result;
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905