当前位置: 首页 > news >正文

做网站界面设计注意什么查网站

做网站界面设计注意什么,查网站,做seo网站空间,网页游戏单机游戏1.http://t.csdnimg.cn/96m2g 此链接提供测试代码; 2.http://t.csdnimg.cn/64iCC 此链接提供测试接口; 关于Webservice的基础部分不做赘述,下面贴上我的测试代码(属于动态调用Webservice): 1&#xff…

1.http://t.csdnimg.cn/96m2g

此链接提供测试代码;

2.http://t.csdnimg.cn/64iCC

此链接提供测试接口;

关于Webservice的基础部分不做赘述,下面贴上我的测试代码(属于动态调用Webservice):

1:http助手类

using System.Net;
using System.Text;
using System.Web;
using static System.Net.Mime.MediaTypeNames;namespace WebServiceGetWeather;public class HttpHelper
{private static HttpHelper m_Helper;/// <summary>/// 单例模式/// </summary>public static HttpHelper Helper{get { return m_Helper ?? (m_Helper = new HttpHelper()); }}/// <summary>/// 获取请求的数据/// </summary>/// <param name="strUrl">请求地址</param>/// <param name="requestMode">请求方式</param>/// <param name="parameters">参数</param>/// <param name="requestCoding">请求编码</param>/// <param name="responseCoding">响应编码</param>/// <param name="timeout">请求超时时间(毫秒)</param>/// <returns>请求成功响应信息,失败返回null</returns>public string GetResponseString(string strUrl, ERequestMode requestMode,  Dictionary<string,string> parameters, Encoding requestCoding, Encoding responseCoding, int timeout = 300){string url = VerifyUrl(strUrl);HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));HttpWebResponse webResponse = null;switch (requestMode){case ERequestMode.Get:webResponse = GetRequest(webRequest, timeout);break;case ERequestMode.Post:webResponse = PostRequest(webRequest, parameters, timeout, requestCoding);break;}if (webResponse != null && webResponse.StatusCode == HttpStatusCode.OK){using (Stream newStream = webResponse.GetResponseStream()){if (newStream != null)using (StreamReader reader = new StreamReader(newStream, responseCoding)){string result = reader.ReadToEnd();return result;}}}return null;}/// <summary>/// get 请求指定地址返回响应数据/// </summary>/// <param name="webRequest">请求</param>/// <param name="timeout">请求超时时间(毫秒)</param>/// <returns>返回:响应信息</returns>private HttpWebResponse GetRequest(HttpWebRequest webRequest, int timeout){try{webRequest.Accept = "text/html, application/xhtml+xml, application/json, text/javascript, */*; q=0.01";webRequest.Headers.Add("Accept-Language", "zh-cn,en-US,en;q=0.5");webRequest.Headers.Add("Cache-Control", "no-cache");webRequest.UserAgent = "DefaultUserAgent";//webRequest.ContentType = "application / json";webRequest.Timeout = timeout;webRequest.Method = "GET";// 接收返回信息HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();return webResponse;}catch (Exception ex){return null;}}/// <summary>/// post 请求指定地址返回响应数据/// </summary>/// <param name="webRequest">请求</param>/// <param name="parameters">传入参数</param>/// <param name="timeout">请求超时时间(毫秒)</param>/// <param name="requestCoding">请求编码</param>/// <returns>返回:响应信息</returns>private HttpWebResponse PostRequest(HttpWebRequest webRequest, Dictionary<string, string> parameters, int timeout, Encoding requestCoding){try{// 拼接参数string postStr = string.Empty;if (parameters != null){parameters.All(o =>{if (string.IsNullOrEmpty(postStr))postStr = string.Format("{0}={1}", HttpUtility.UrlEncode(o.Key), HttpUtility.UrlEncode(o.Value));elsepostStr += string.Format("&{0}={1}", HttpUtility.UrlEncode(o.Key), HttpUtility.UrlEncode(o.Value));return true;});}byte[] byteArray = requestCoding.GetBytes(postStr);webRequest.Accept = "text/html, application/xhtml+xml, application/json, text/javascript, */*; q=0.01";webRequest.Headers.Add("Accept-Language", "zh-cn,en-US,en;q=0.5");webRequest.Headers.Add("Cache-Control", "no-cache");webRequest.UserAgent = "DefaultUserAgent";//webRequest.Timeout = timeout;webRequest.ContentType = "application/x-www-form-urlencoded";webRequest.ContentLength = byteArray.Length;webRequest.Method = "POST";// 将参数写入流using (Stream newStream = webRequest.GetRequestStream()){newStream.Write(byteArray, 0, byteArray.Length);newStream.Close();}// 接收返回信息HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();return webResponse;}catch (Exception ex){return null;}}/// <summary>/// 验证URL/// </summary>/// <param name="url">待验证 URL</param>/// <returns></returns>private string VerifyUrl(string url){if (string.IsNullOrEmpty(url))throw new Exception("URL 地址不可以为空!");if (url.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase))return url;return string.Format("http://{0}", url);}
}
public enum ERequestMode
{Get,Post
}

2:调用方法

internal class Program{static void Main(string[] args){Console.WriteLine("Hello, World!");TestInvoke();}/// <summary>/// 测试调用/// </summary>static void TestInvoke(){//组织参数//<参数名,参数值>Dictionary<string, string> parameters = new Dictionary<string, string>();parameters.Add("byProvinceName", "北京");//getSupportCity是方法名称直接放在后面string url = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getSupportCity ";string _result = HttpHelper.Helper.GetResponseString(url, ERequestMode.Post, parameters, Encoding.Default, Encoding.UTF8);}

注意事项:

1:接口方法里面的案例参数要与代码中指定的一致:

 2:方法名直接放在url结尾:

string url = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getSupportCity ";

△   其中getSupportCity 就是方法名。

Dictionary<string, string> parameters = new Dictionary<string, string>();

△   其中parameters 的key是方法参数名,value是参数值。

先装一下原创,原作有想法评论或者私聊,即可更改。

http://www.dinnco.com/news/70445.html

相关文章:

  • 网站开发名片线上销售渠道有哪几种
  • 专门做狗猫配套网站有什么意思查询域名注册信息
  • 佛山市多语言营销型网站建站高端网站设计
  • 公司做网站推广查询网站流量
  • 网站建设方案范例淄博seo网络公司
  • 宁波做网站seo的合肥seo推广培训班
  • 做网站分前台后端吗seo兼职怎么收费
  • 公装网站怎么做win10优化大师怎么样
  • 延吉做网站ybdiran国内最大的搜索引擎
  • web网站开发技术说明友链外链app
  • WordPress迁移网站打不开个人开发app可以上架吗
  • 关于文化馆网站建设的材料产品网络推广怎样做
  • 企业网站建设专业的公司教育培训机构排名
  • 搭建一个服务器买域名做网站广州网络推广服务商
  • 武汉品牌网站建设上海优化公司排行榜
  • 东明网站建设推广ai智能搜索引擎
  • 济宁做网站多少钱网站搜索排名查询
  • 哪家网站制作 优帮云seo白帽优化
  • 物流网站毕业设计论文免费建站网站
  • 绵阳网站建设推广郑州网站关键词排名技术代理
  • 网站维护的内容2020年度关键词有哪些
  • 阳江seo网站推广竞价是什么工作
  • 韶山网站建设深圳网站设计
  • qq刷赞网站怎么做的百度seo是什么意思
  • 北京网站建设价格便宜在线咨询
  • 网站与网站链接怎么做重庆seo技术博客
  • 门户网站建设预算表谷歌下载安装
  • 营销成功案例网站全国今日新增疫情
  • 怎么做游戏推广网站头条新闻 最新消息条
  • 设计师培训班费用钦州seo