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码而前端界面中中文显示不出来!!!开始怀 ...
随机推荐
- C#中调用user32.dll库的keybd_Event函数,操作键盘
keybd_event()的函数原型是: void keybd_event( byte bVk, //虚拟键码 byte bScan, //该键的硬件扫描码 dword ...
- SpringMVC整合Hibernate实现增删改查之按条件查询
首先我贴出我项目的结构,只完成了条件查询的相关代码,增删改没有写. 1.新建一个动态Web工程,导入相应jar包,编写web.xml配置文件 <context-param> <par ...
- iOS设置cell选中时文字颜色的变化
cell.titleStr.highlightedTextColor = EMCGreenColor;
- 对jquery分页的升级
以前写的分页用了好久了,但是分页时除了传页面外有时还要传一些其它参数,以前操作时要把传的参数放到隐藏hidden中,分页时在取出来,这样比较麻烦,今天无事,重新包装了一下 直接上代码吧 css用了bo ...
- github创建文件夹
网页上只能通过在创建新文件的时候顺便创建文件夹(文件夹与文件用 / 隔开),例如home/test.md就在该仓库下创建了一个文件夹home,该文件夹下有一个新的文件test.md
- git push :推送本地更改到远程仓库的三种模式
摘要:由于在git push过程中,no-fast-forward 的push会被拒绝,如何解决git push失败的问题?这里面有三种方法,分别会形成merge形式的提交历史,线性形式的提交历史,覆 ...
- dd-wrt 定时重连 pppoe 更换ip地址
因为做代理,IP时常被封的原因,所以,需要每天定时重启路由器,重启路由器影响太大,所以重新拨号是一个更好的选择. 在dd-wrt里面,杀掉pppoe服务进程就可以了,这个进程会自动重新启动,然后就相当 ...
- 很好用的request转换为实体方法还有判断实体所有参数不能为空的方法
/// <summary> /// 模型辅助处理类 /// 2016-04-18 /// </summary> public class ModelHelper { /// & ...
- Spring学习笔记之三----基于Annotation的Spring IOC配置
使用Annotation 来创建Bean有两种方式 在配置类中创建bean(配置类是指标注为@Configuration的类),在配置类中每一个创建bean的方法都应该标注为@Bean,可以在@Bea ...
- mysql 数据库故障通过备份恢复模拟