在服务端发起一个Post请求
1.http://www.tuling123.com/openapi/api?key=9d2ff29d44b54e55acadbf5643569584&info=?
上面这个请求在服务端发起
/// <summary>
/// 构造url的参数ajax的data值
/// </summary>
/// <param name="dic"></param>
/// <returns></returns>
public static string GetUrlStr(Dictionary<string, string> dic) {
StringBuilder sb = new StringBuilder();
foreach (var item in dic) {
sb.AppendFormat("{0}={1}&", item.Key, item.Value);
}
string urlStr = sb.Remove(sb.Length - , ).ToString();
return urlStr;
} /// <summary>
/// 发送post请求
/// </summary>
/// <param name="postData"></param>
/// <param name="postUrl"></param>
/// <returns></returns>
public static string SendHttpPostRequest(string postData,string postUrl) {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postUrl);
byte[] data = Encoding.GetEncoding("gbk").GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream()) {
stream.Write(data, , data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
return responseString;
}
2.将参数进行编码后调用
protected void Page_Load(object sender, EventArgs e) {
Dictionary<string, string> test = new Dictionary<string, string>();
test.Add("info", System.Web.HttpUtility.UrlEncode("笑话"));
string paream = Utility.GetUrlStr(test);
string result = Utility.SendHttpPostRequest(paream, "http://www.tuling123.com/openapi/api?key=9d2ff29d44b54e55acadbf5643569584");
Response.Write(result);
}
3.结果
在服务端发起一个Post请求的更多相关文章
- 服务端如何获取客户端请求IP地址
服务端获取客户端请求IP地址,常见的包括:x-forwarded-for.client-ip等请求头,以及remote_addr参数. 一.remote_addr.x-forwarded-for.cl ...
- 客户端 new socket时候 就像服务端发起连接了
客户端 new socket时候 就像服务端发起连接了
- 微信小程序初见+nodejs服务端 (一个简单的博客)
推荐网址: 腾讯云快速开发(nodejs前后端):https://developers.weixin.qq.com/miniprogram/dev/qcloud/qcloud.html#%E5%AF% ...
- Binder学习笔记(九)—— 服务端如何响应Test()请求 ?
从服务端代码出发,TestServer.cpp int main() { sp < ProcessState > proc(ProcessState::self()); sp < I ...
- socket基础实例(一个服务端对应一个客户端情形)
服务端处理1个客户端的例子 运行结果: (1) while(accept+if(recv)) 情形 执行服务端进程: [root@localhost single_link]# ./server [s ...
- GOLang(第二篇 发起一个Http请求)
import ( "net/http" "net/url" ) //发送一个简单的get请求 func GetRequest { //联系使用 make(map ...
- Verify an App Store Transaction Receipt 【苹果服务端 验证一个应用程序商店交易收据有效性】
转自:http://blog.csdn.net/saindy5828/article/details/6414014 1. 从Transaction 的TransactionReceipt属性中得到接 ...
- 客户端与服务端Post报文构造请求及Http Post与Get请求方法
客户端 namespace Client.Controllers { public class HomeController : Controller { // // GET: /Home/ publ ...
- Jmeter 如何发起一个Get请求
举例平台:https://www.juhe.cn/docs/api/id/65 前提条件: 1)要在聚合网站注册实名认证才可以收到Key,用于Get请求的参数数值 2)Jmeter本地安装好 3.这是 ...
随机推荐
- blog postman 翻译(2):postman中新增request attributes 的描述(desc)
blog的原文链接是:http://blog.getpostman.com/2017/06/03/descriptions-for-request-attributes-in-postman/ pos ...
- select 动态添加 获取 整理
比如<select class="selector"></select> 1.设置value为pxx的项选中 $(".selector" ...
- 系统封装的dispatch系列代码块引起的循环引用
整整一天的时间都在找内存泄漏,唯独遗漏了这个代码块,结果就是它,希望大家以后注意. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)( ...
- maven构建的模块化的JavaWeb工程
最近对maven构建的模块化的JavaWeb工程,比较感兴趣,所以自己就想从头弄一个出来,在此做一个记录,供以后学习. 前置条件:电脑上有eclipse(或者myeclipse,记事本也可以,那样就得 ...
- 如何让IE7,IE8支持css3
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 原理:在用ie浏览 ...
- 中矿大新生赛 G 甄总搬石头【优先队列/哈夫曼/贪心】
时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld 题目描述 https://www.nowcoder.com/ ...
- Python与数据库[2] -> 关系对象映射/ORM[4] -> sqlalchemy 的显式 ORM 访问方式
sqlalchemy 的显式 ORM 访问方式 对于sqlalchemy,可以利用一种显式的ORM方式进行访问,这种方式无需依赖声明层,而是显式地进行操作.还有一种访问方式为声明层 ORM 访问方式. ...
- Loj #6019. 「from CommonAnts」寻找 LCM
给个链接:https://loj.ac/problem/6019 还是一道扩展卢卡斯+中国剩余定理....就当练练手 但是这题怎么这么卡常呢????!!!!! 在LOJ上死也过不去 (为什么要加那么多 ...
- BZOJ 3864 Hero Meets Devil
题目大意 给定一个由AGCT组成的串\(t\), 求对于所有的\(L \in [1, |t|]\), 有多少个由AGCT组成的串\(s\)满足\(LCS(s, t) = L\). Solution 传 ...
- How to create an IPA (Xcode 5)
This tutorial will walk you through the easiest way to generate an IPA using Xcode 5. We will be usi ...