①服务方法

       [HttpGet]//get服务
public JsonResult GetUserName(int id)
{
try
{
IXiao_UserBLL bll = new Xiao_UserBLL();
var model = bll.GetUserById(ConnectPool.connect, id);
return Json(model.Name,JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
return null;
}
}
[HttpPost] //post服务
public JsonResult GetUserPost(int id)
{
try
{
IXiao_UserBLL bll = new Xiao_UserBLL();
var model = bll.GetUserById(ConnectPool.connect, id);
return Json(model, JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
return null;
}
}

服务需要发布后才可以请求的到

②Get请求服务

   public string Login(int userid)
{
try
{
var id = userid;
var url = "http://www.xiaoyaodijun.club/home/GetUserName/" + id;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
string json = streamReader.ReadToEnd(); return null;
}
catch
{
return "error";
}
}
③Post请求服务

        public string GetOneUser(int userid)
{
try
{
var url = "http://www.xiaoyaodijun.club/home/GetUserPost/";
var param = "id="+userid;
byte[] bs = Encoding.ASCII.GetBytes(param);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
//这个标识文件类型。application/octet-stream表示二进制数据。
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = bs.Length;
using (Stream str = request.GetRequestStream())
{
str.Write(bs, , bs.Length);
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
string json = streamReader.ReadToEnd();
}
return null;
}
catch
{
return "error";
}
}

请求http服务的更多相关文章

  1. Oracle几个基础配置问题:ORA-12154: TNS: 无法解析指定的连接标识符、ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务、ORA-12516 TNS监听程序找不到符合协议堆栈要求的可用处理程序

    问题1:ORA-12154: TNS: 无法解析指定的连接标识符 在一台服务器上部署了Oracle客户端,使用IP/SID的方式访问,老是报ORA-12154错误,而使用tnsnames访问却没有问题 ...

  2. Node.js 使用 soap 模块请求 WebService 服务接口

    项目开发中需要请求webservice服务,前端主要使用node.js 作为运行环境,因此可以使用soap进行请求. 使用SOAP请求webservice服务的流程如下: 1.进入项目目录,安装 so ...

  3. 安装完oracle重新启动后报ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务(重启前正常)

    安装完oracle重新启动后报ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务(重启前正常) 刚安装完后用plSql登录正常. 在dos命令行下 输入  sqlplus 用户 ...

  4. Android应用程序请求SurfaceFlinger服务渲染Surface的过程分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/7932268 在前面一篇文章中,我们分析了And ...

  5. Android应用程序请求SurfaceFlinger服务创建Surface的过程分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/7884628 前面我们已经学习过Android应 ...

  6. sql2008r2,以前好好可以用的,但装了vs2017后,连接不上了,服务也停了,结果手动也 启动不了, 无法加载或初始化请求的服务提供程

    日志: 2017-12-14 12:33:17.53 服务器 A self-generated certificate was successfully loaded for encryption.2 ...

  7. http客户端请求及服务端详解

    http客户端请求及服务端详解 引言 HTTP 是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和 扩展. ...

  8. kmspico_setup.exe运行提示系统资源不足,无法完成请求的服务

    在使用KMSpico激活office时,windows下运行exe会提示系统资源不足,无法完成请求的服务. 我的解决方法是:卸载电脑上的wps...

  9. node socket :10106无法加载或初始化请求的服务提供程序

    node socket :10106无法加载或初始化请求的服务提供程序 无端端的,不知道怎么回事,node突然就坏掉 了,应该是某些配置无意中改动了,问题如下: 目前能想到的解决办法就是:重置配置,用 ...

  10. python服务器端、客户端的模型,客服端发送请求,服务端进行响应(web.py)

    服务器端.客户端的模型,客服端发送的请求,服务端的响应 相当于启动了一个web server install web.py 接口框架用到的包 http://webpy.org/tutorial3.zh ...

随机推荐

  1. $(this) 和 this

    在使用 jQuery 时,$(this) 和 this 具体指: this :是当前 DOM 对象: $(this) 是jQuery对象: 例子: <input type="text& ...

  2. Android 根据EditText搜索框ListView动态显示数据

    根据EditText搜索框ListView动态显示数据是根据需求来的,觉得这之中涉及的东西可能比较的有意思,所以动手来写一写,希望对大家有点帮助. 首先,我们来分析下整个过程: 1.建立一个layou ...

  3. iOS的Ping++支付接入步骤(详细)

    Ping++ SDK 代码下载地址: https://github.com/CoderLeezhen/PingppDemo 参考链接: https://www.pingxx.com/guidance/ ...

  4. api (二) 创建控件 (转)

    在Win32 SDK环境下,怎么来创建常用的那些基本控件呢?我们知道如果用MFC,简单的拖放即可完成大多数控件的创建,但是我们既然是用Windows SDK API编程,当然是从根上解决这个问题,实际 ...

  5. Linux学习之/etc/init.d/functions详解

    转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=28773997&id=3996557 /etc/init.d/f ...

  6. You have not agreed to the Xcode license.

    You have not agreed to the Xcode license. Before running the installer again please agree to the lic ...

  7. sqlserver 分页sql语句

     select * from (select *,row_number() over(order by CONTENT_ID ) as rnum from ArchiveContents) t whe ...

  8. Xampp Linux应用

    一.基本操作: 1.Xampp安装包下载:   https://www.apachefriends.org/index.html   2.安装与配置:   将xampp-linux-x64-5.6.3 ...

  9. 占成本85% SSD深度选购教你如何看颗粒

    颗粒是固态硬盘负责容量和传输的介质,在这一方面上与优盘产品是相同的,从外观上看,颗粒占据了整个固态硬盘内部70%左右的空间,其同样做为成本技术,根据厂商的用料不同,成为了固态硬盘内部核心材料. 颗粒的 ...

  10. 九度OnlineJudge之1021:统计字符

    题目描述:     统计一个给定字符串中指定的字符出现的次数. 输入:     测试输入包含若干测试用例,每个测试用例包含2行,第1行为一个长度不超过5的字符串,第2行为一个长度不超过80的字符串.注 ...