c#_1:后台post请求
1:aspx内容
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Push.aspx.cs" Inherits="_jichu_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
#submit_Push
{
}
</style>
</head>
<body>
<form id="form_Push" runat="server">
<div style="margin: 0 auto; width: 800px">
<table>
<tr>
<td>车款ID:</td>
<td>
<input type="text" id="text_CarModelID" runat="server" readonly="true" />
</td>
</tr>
<tr>
<td>VIN码:</td>
<td>
<input type="text" id="text_Vin" runat="server" readonly="true" />
</td>
</tr>
<tr>
<td>发动机号:</td>
<td>
<input type="text" id="text_EngineNumber" runat="server" readonly="true" />
</td>
</tr>
<tr>
<td>车牌号:</td>
<td>
<input type="text" id="text_CarBrandNumber" runat="server" />
</td>
</tr>
<tr>
<td>车辆归属地:</td>
<td>
<select id="select_CarProvince" runat="server">
<option>北京市</option>
<option>河南省</option>
</select>
<select id="select_CarCity" runat="server">
<option>北京市</option>
<option>郑州市</option> </select>
<select id="select_CarDistrict" runat="server">
<option>海淀区</option>
<option>中原区</option>
</select>
</td>
</tr>
<tr>
<td>车辆购置价:</td>
<td>
<input type="text" id="text_PurchasePrice" runat="server" />
</td>
</tr>
<tr>
<td>初登日期:</td>
<td>
<input type="text" id="text_RegisterDate" runat="server" readonly="true" value="2012-6-1" />
</td>
</tr>
<tr>
<td>发票日期:</td>
<td>
<input type="text" id="text_InvoiceDate" runat="server" value="2012-8-1" />
</td>
</tr>
<tr>
<td>客户姓名:</td>
<td>
<input type="text" id="text_ClientName" runat="server" readonly="true" />
</td>
</tr>
<tr>
<td>客户手机:</td>
<td>
<input type="text" id="text_ClientPhone" runat="server" readonly="true" />
</td>
</tr>
<tr>
<td>证件类型:</td>
<td>
<input type="text" id="text_PapersType" runat="server" readonly="true" />
</td>
</tr>
<tr>
<td>证件号码:</td>
<td>
<input type="text" id="text_PapersNumber" runat="server" readonly="true" />
</td>
</tr>
<tr>
<td>客户所在地:</td>
<td>
<select id="select_ClientProvince" runat="server">
<option>北京市</option>
<option>河南省</option>
</select>
<select id="select_ClientCity" runat="server">
<option>北京市</option>
<option>郑州市</option>
</select>
<select id="select_ClientDistrict" runat="server">
<option>海淀区</option>
<option>中原区</option>
</select>
详细地址:<input type="text" runat="server" id="text_ClientAddress" />
</td>
</tr>
<tr>
<td>客户邮编:</td>
<td>
<input type="text" id="text_ClientPost" runat="server" />
</td>
</tr>
<tr>
<td>客户邮箱:</td>
<td>
<input type="text" id="text_ClientEmail" runat="server" />
</td>
</tr>
<tr>
<td>新旧程度:</td>
<td>
<select id="select_CarDegree" runat="server">
<option>二手车</option>
<option>新车</option>
</select>
</td>
</tr>
<tr>
<td>签约时间:</td>
<td>
<input type="text" id="text_SingDate" runat="server" />
</td>
</tr>
<tr>
<td>生效时间:</td>
<td>
<input type="text" id="text_TakeEffectDate" runat="server" />
</td>
</tr>
<tr>
<td>起始公里数:</td>
<td>
<input type="text" id="text_StartKM" runat="server" />
</td>
</tr>
<tr>
<td>产品名称:</td>
<td>
<select id="select_ProdutName" runat="server">
<option>专享A套餐</option>
<option>268V-B套餐</option>
</select>
</td>
</tr>
<%-- <tr>
<td>产品类别:</td>
<td>
<select id="select_ProdutType" runat="server">
<option>动力智选-Day1</option>
</select>
</td>
</tr>--%>
<tr>
<td>销售公司:</td>
<td>
<input type="text" id="text_SaleCompany" runat="server" />
</td>
</tr>
<tr>
<td>附件:</td>
<td>
<span id="span_Enclosure" runat="server">附件1|附件2</span>
</td>
</tr>
<tr>
<td>合同备注:</td>
<td>
<textarea id="text_ContractRemarks" runat="server"></textarea>
</td>
</tr>
<tr>
<td>
<asp:Button ID="submit_Push" runat="server" OnClick="BtnSubmit" Text="推送" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
2:aspx.cs内容
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json; public partial class _jichu_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetValue();
}
} private void GetValue()
{
text_CarModelID.Value = "";
text_Vin.Value = "D1111111111111121";
text_EngineNumber.Value = "D1111111111111111";
text_CarBrandNumber.Value = "京D11111";
text_PurchasePrice.Value = "";
text_RegisterDate.Value = "2016-6-1";
text_InvoiceDate.Value = "2016-6-1";
text_ClientName.Value = "客户姓名";
text_ClientPhone.Value = "";
text_PapersType.Value = "身份证";
text_PapersNumber.Value = "";
text_ClientAddress.Value = "客户地址";
text_ClientPost.Value = "客户邮编";
text_ClientEmail.Value = "客户邮箱";
text_SingDate.Value = "2016-6-1";
text_TakeEffectDate.Value = "2016-6-1";
text_StartKM.Value = "";
span_Enclosure.InnerText = "https://www.baidu.com/img/bd_logo.png|https://www.baidu.com/img/bd_logo1.png";
text_SaleCompany.Value = "销售公司";
text_ContractRemarks.Value = "合同备注";
} #region 点击推送
public void BtnSubmit(object sender, EventArgs e)
{
JsonModel model_Json = new JsonModel();
model_Json.A = text_CarModelID.Value;
model_Json.B = text_Vin.Value;
model_Json.C = text_EngineNumber.Value;
model_Json.D = text_CarBrandNumber.Value;
model_Json.E1 = select_CarProvince.Value;
model_Json.E2 = select_CarCity.Value;
model_Json.E3 = select_CarDistrict.Value;
model_Json.F = text_PurchasePrice.Value;
model_Json.G = text_RegisterDate.Value;
model_Json.H = text_InvoiceDate.Value;
model_Json.I = text_ClientName.Value;
model_Json.J = text_ClientPhone.Value;
model_Json.K = text_PapersType.Value;
model_Json.L = text_PapersNumber.Value;
model_Json.M1 = select_ClientProvince.Value;
model_Json.M2 = select_ClientCity.Value;
model_Json.M3 = select_ClientDistrict.Value;
model_Json.M4 = text_ClientAddress.Value;
model_Json.N = text_ClientPost.Value;
model_Json.N1 = text_ClientEmail.Value;
model_Json.O = select_CarDegree.Value;
model_Json.P = text_SingDate.Value;
model_Json.Q = text_TakeEffectDate.Value;
model_Json.R = text_StartKM.Value;
model_Json.S = select_ProdutName.Value;
model_Json.T = span_Enclosure.InnerText; //附件需绝对路径
model_Json.U = text_SaleCompany.Value;
model_Json.X = text_ContractRemarks.Value;
model_Json.Y = "hina";
model_Json.Z = "8A2399F8DC0C8F15CEB4";
string result = PostData("http://localhost:6385/Web/GetPush_Zs.ashx", JsonConvert.SerializeObject(model_Json), Encoding.UTF8);
ResultMSG model_ResultMSG = JsonConvert.DeserializeObject<ResultMSG>(result);
//执行操作数据库
}
#endregion #region Post访问外部地址
/// <summary>
/// Post访问外部地址
/// </summary>
/// <param name="url">调用的URL</param>
/// <param name="paraData">参数</param>
/// <param name="encoding">编码格式(传空为默认的编码)</param>
/// <returns></returns>
public static string PostData(string url, string paraData, Encoding encoding)
{
if (string.IsNullOrEmpty(paraData))
{
return string.Empty;
}
try
{
byte[] dataPara = UTF8Encoding.UTF8.GetBytes(paraData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = dataPara.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(dataPara, , dataPara.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader strRead = null;
if (encoding != null)
{
strRead = new StreamReader(response.GetResponseStream(), encoding);
}
else
{
strRead = new StreamReader(response.GetResponseStream());
}
string result = strRead.ReadToEnd();
newStream.Close();
strRead.Close();
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion #region 接收post
private string PostInput(HttpContext context)
{
try
{
System.IO.Stream s = context.Request.InputStream;
int count = ;
byte[] buffer = new byte[];
StringBuilder builder = new StringBuilder();
while ((count = s.Read(buffer, , )) > )
{
builder.Append(Encoding.UTF8.GetString(buffer, , count));
}
s.Flush();
s.Close();
s.Dispose();
return builder.ToString();
}
catch (Exception ex)
{ throw ex; }
}
#endregion } public class JsonModel
{
public string A { get; set; }
public string B { get; set; }
public string C { get; set; }
public string D { get; set; }
public string E1 { get; set; }
public string E2 { get; set; }
public string E3 { get; set; }
public string F { get; set; }
public string G { get; set; }
public string H { get; set; }
public string I { get; set; }
public string J { get; set; }
public string K { get; set; }
public string L { get; set; }
public string M1 { get; set; }
public string M2 { get; set; }
public string M3 { get; set; }
public string M4 { get; set; }
public string N { get; set; }
public string N1 { get; set; }
public string O { get; set; }
public string P { get; set; }
public string Q { get; set; }
public string R { get; set; }
public string S { get; set; }
public string T { get; set; }
public string U { get; set; }
public string X { get; set; }
public string Y { get; set; }
public string Z { get; set; }
} /// <summary>
/// 结果信息
/// </summary>
public class ResultMSG
{
public string message { get; set; }
public string htNO { get; set; }
public DateTime htCreatTime { get; set; }
public string htRemark { get; set; }
public DateTime htEndTime { get; set; }
public int htEndKM { get; set; }
public float htMoney { get; set; }
public string htContractKey { get; set; }
}
c#_1:后台post请求的更多相关文章
- Flask04 后台获取请求数据、视图函数返回类型、前台接受响应数据
1 后台获取请求数据 1.1 提出问题 前台发送请求的方式有哪些 后台如何获取这些请求的参数 1.2 前台发送请求的方式 GET.POST.AJAX 点睛:如果不指定请求方式,浏览器默认使用GET请求 ...
- 后台web请求代码(含https,json提交)
后台web请求 namespace XXXX.Utilites { using System; using System.Collections.Generic; using System.IO; u ...
- node后台fetch请求数据-Hostname/IP doesn't match certificate's altnames解决方法
一.问题背景 基于express框架,node后台fetch请求数据,报错Hostname/IP doesn't match certificate's altnames..... require(' ...
- aes加解密后续问题contentType不是application/json时候后台解析请求对象request
一.post请求的三种content-type 1.application/x-www-form-urlencoded 主要用于如下:1.1: 最常见的POST提交数据方式.1.2:原生form默认的 ...
- ajax 请求成功,但是后台feigin请求超时解决方案
========后台请求数据时间较长,报feigin超时错误====== fegin报错如下: feign.RetryableException: Read timed out executing P ...
- 利用SPM工具运行自己创建的小组件(使用common-model向后台接口请求数据)
步骤如下: 1.安装依赖:spm install -e 2.编译:spm build (编译好的东西会放在trunk-dist里面) 3.发布:spm app -d (会出来一个export端口,一般 ...
- JavaScript当页面关闭时向后台发送请求
今天做项目时遇上一个需求,当浏览器或页面关闭时将数据存储到数据库内.实现思想是采用js监测onunload然后发送请求.结果失败,刷新可以发送但是关闭并不能,整了一整天并没有解决,最后找到了解决办法. ...
- 后台模拟请求 HttpHelper 序列化 MD5 时间戳
使用场景 C# 服务器后台调用其他服务器并处理 场景 /// <summary> /// 获取用户信息 /// </summary> /// <param name=&q ...
- java后台发送请求并获取返回值(续)
在java后端发送请求给另一个平台,从而给前端实现 "透传"的过程中,出现:数据请求到了并传到了前端,但是控制台打印时中文显示Unicode码而前端界面中中文显示不出来!!!开始怀 ...
随机推荐
- 鸟哥linux私房菜基础篇
1)注销:exit2)指令太长:命令太长的时候,可以使用反斜杠 (\) 来跳脱[Enter]符号,使挃令连续到下一行3)系统语言显示和设置命令:echo $LANG,显示当前系统语言:简体中文zh_C ...
- Intellij IDE 常用设置
1· 去除代码提示的Case sensitive(比如Sprite,键入sprite不进行任何提示) Editor->Code Completion->Case sensitive com ...
- Unity和Android互相调用
安卓部分代码: public class GameMainActivity extends UnityPlayerActivity { private static String CODE_ROOT ...
- iOS设置cell选中时文字颜色的变化
cell.titleStr.highlightedTextColor = EMCGreenColor;
- 用js计算从开始到结束时间之内的按周值选定
前台选择周几(周一周日),比如选择<td>周一</td>,<td>周三</td>,<td>周五</td>我用js attr 给t ...
- hdu5714 拍照[2016百度之星复赛C题]
由于船移动的速度都一样,那么对于往一个方向的船相对距离其实是不变的,我们可以把往一个方向移动的船都视作静止,并求出在哪些观测位置可以看到,很明显对于船[x,y,z],当x+z>=y-z的时候,可 ...
- Select For update语句浅析 (转)
Select … for update语句是我们经常使用手工加锁语句.通常情况下,select语句是不会对数据加锁,妨碍影响其他的DML和DDL操作.同时,在多版本一致读机制的支持下,select语句 ...
- Final阶段用户调查报告
组名称:nice! 项目名称:约跑 小组成员:李权(组长).刘芳芳.于淼.宫丽君.韩媛媛 产品下载地址:http://pan.baidu.com/s/1mhIjaS4 问卷时间:2016年12月2号1 ...
- java图书管理的一个小模块(增删改查,不使用数据库)
图书管理模块:某图书管需要对图书进行信息化管理,要求管理员能够进行新增图书,能按照书名进行模糊查看图书能进行价格统计 系统实现如下:1.新增2.查询3.统计价格 1请输入新书:图书号,书名,作者,价格 ...
- Oracle Partition By 的使用
1.概述 Parttion by 关键字是Oracle中分析性函数的一部分,它和聚合函数不同的地方在于它能够返回一个分组中的多条记录,儿聚合函数一般只有一条反映统计值的结果. 2.使用方式 场景:查询 ...