C# HttpHelper万能框架实现 接口

POST请请求是使用Http协议与请求的URL进行连接,然后再写入数据,最后关闭连接的过程

方法(1)

    

//要Post的数据
string postdate = "a=123&c=456&d=789" ;
//将Post数据转为字节数组
byte [] bytedate = System.Text.Encoding.UTF8.GetBytes(postdate);
//创建Httphelper对象
HttpHelper http = new HttpHelper();
//创建Httphelper参数对象
HttpItem item = new HttpItem()
{
     URL = "http://www.sufeinet.com" ,//URL     必需项   
     Method = "post" , //URL     可选项 默认为Get  
     ContentType = "application/x-www-form-urlencoded" , //返回类型    可选项有默认值
     PostDataType = PostDataType.Byte,
     PostdataByte = bytedate
};
//请求的返回值对象
HttpResult result = http.GetHtml(item);
//获取请请求的Html
string html = result.Html;
//获取请求的Cookie
string cookie = result.Cookie;
 
 
 
方法(2)

public static string Url = System.Web.Configuration.WebConfigurationManager.AppSettings["RemoteUrl"];
        public static void Add(FaceItem item) {


            try
            {
                HttpHelper http = new HttpHelper();
                HttpItem hitem = new HttpItem()
                {

                    Method = "post",//URL     可选项 默认为Get  
                    ContentType = "application/x-www-form-urlencoded",
                    URL = Url + "add.action",
                    Postdata = string.Format("f_Id=1&imgLen={0}&imgContent={1}&name={2}&info=",
                                              item.UserGuid, item.ImgLength, item.ImgContent)
                };

                HttpResult result = http.GetHtml(hitem);
                //获取请请求的Html
                string html = result.Html;
                //获取请求的Cookie
                string cookie = result.Cookie;
               // item.ImageId = Guid.NewGuid().ToString();
            }
            catch(Exception ex) {
                //记录错误
            }

            //测试使用
            item.ImageId = Guid.NewGuid().ToString();

        }

苏飞论坛

http://www.sufeinet.com/thread-9993-1-1.html

 

转载于:https://www.cnblogs.com/1955/p/7838909.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值