• 大小: 2KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: 其他
  • 标签: Post  get方式  webapi  

资源简介

.net 后台Post,get方式调用webapi,包括上传文件

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.IO;

namespace IceMakeCommon
{
    public class HttpHelper
    {
        public static string GetHttpContentType(string ext)
        {
            string cType = “image/jpeg“;
            switch (ext.ToLower())
            {
                case “.jpg“:
                case “.jpeg“:
                    cType = “image/jpeg“;
                    break;
                case “.png“:
                    cType = “image/png“;
                    break;
                case “.bmp“:
                    cType = “image/bmp“;
                    break;
                case “.gif“:
                    cType = “image/gif“;
                    break;
                default:
                    cType = “application/octet-stream“;
                    break;
            }
            return cType;
        }

        /// 
        /// 模拟http post请求
        /// 

        /// 
        /// 
        /// 
        public static string CreateHttpPostResponse(string url IDictionary parameters)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException(“url“);
            }

            HttpWebRequest request = null;
            //如果是发送HTTPS请求   
            if (url.StartsWith(“https“ StringComparison.OrdinalIgnoreCase))
            {
                //ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                //request = WebRequest.Create(url) as HttpWebRequest;
                //request.ProtocolVersion = HttpVersion.Version10;
            }
            else
            {
                request = WebRequest.Create(url) as HttpWebRequest;
            }
            request.Method = “POST“;

            request.Headers.Add(“X_REG_CODE“ “288a633ccc1“);
            request.Headers.Add(“X_MACHINE_ID“ “a306b7c51254cfc5e22c7ac0702cdf87“);
            request.Headers.Add(“X_REG_SECRET“ “de308301cf381bd4a37a184854035475d4c64946“);
            request.Headers.Add(“X_STORE“ “0001“);
            request.Headers.Add(“X_BAY“ “0001-01“);
            request.Headers.Add(“X-Requested-With“ “xmlHttpRequest“);
            request.ContentType = “application/x-www-form-urlencoded“;
            request.Headers.Add(“Accept-Language“ “zh-CN“);
            request.Headers.Add(“Accept-Encoding“ “gzip deflate“);
            request.Accept = “*/*“;

            request.CookieContainer = new CookieContainer();

            //如果需要POST数据   
            if (!(parameters == null || parameters.Count == 0))
            {
                StringBuilder buffer = new StringBuilder();
                int i = 0;
                foreach (string key

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      10554  2015-03-06 16:48  .net 后台Post,get方式调用webapi\HttpHelper.cs

     目录          0  2015-03-26 17:28  .net 后台Post,get方式调用webapi

----------- ---------  ---------- -----  ----

                10554                    2


评论

共有 条评论