WebApi的调用-2.后台调用
httpClient调用方式
namespace SOA.Common
{
//httpClient调用WebApi
public class HttpClientHelper
{
public static string GetHttpClient(string serverUrl, string method, WebHeaderCollection header)
{
using (HttpClient client = new HttpClient())
{
//如果有Basic认证的情况下,请自己封装header
if (header != null)
client.DefaultRequestHeaders.Add("Authorization", "BasicAuth " + header["Authorization"]);
var response = client.GetAsync(serverUrl + method).Result; //拿到异步结果
Console.WriteLine(response.StatusCode); //确保http成功
return response.Content.ReadAsStringAsync().Result;
}
}
public static string PostHttpClient(string serverUrl, string method, Dictionary<string, string> param)
{
using (HttpClient client = new HttpClient())
{
var content = new FormUrlEncodedContent(param);
client.DefaultRequestHeaders.Add("user-agent",
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
var response = client.PostAsync(serverUrl + method, content).Result; //拿到异步结果
Console.WriteLine(response.StatusCode); //确保http成功
return response.Content.ReadAsStringAsync().Result;
}
}
/// <summary>
/// httpClient使用代理
/// </summary>
/// <param name="serverUrl"></param>
/// <param name="method"></param>
/// <param name="param"></param>
/// <returns></returns>
public static string PostHttpClientWithProxy(string serverUrl, string method, Dictionary<string, string> param,
ProxyParam proxyParam)
{
HttpClientHandler aHandler = new HttpClientHandler();
aHandler.UseCookies = true;
aHandler.AllowAutoRedirect = true;
IWebProxy Proxya = new WebProxy(proxyParam.IP + ":" + proxyParam.Port);
Proxya.Credentials = new NetworkCredential(proxyParam.Name, proxyParam.Pass, proxyParam.Domain);
aHandler.Proxy = Proxya;
using (HttpClient client = new HttpClient(aHandler))
{
var content = new FormUrlEncodedContent(param);
client.DefaultRequestHeaders.Add("user-agent",
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
var response = client.PostAsync(serverUrl + method, content).Result; //拿到异步结果
Console.WriteLine(response.StatusCode); //确保http成功
return response.Content.ReadAsStringAsync().Result;
}
}
}
public class ProxyParam
{
public string IP { get; set; }
public string Port { get; set; }
public string Name { get; set; }
public string Pass { get; set; }
public string Domain { get; set; }
}
}
httpWebReqeust调用方式(一般使用)
//WebRequest调用WebApi
public class WebRequestHelper
{
/// <summary>
/// WebRequest的 Get 请求
/// </summary>
/// <param name="serverUrl" type="string">
/// <para>
/// api地址(地址+方法)
/// </para>
/// </param>
/// <param name="paramData" type="string">
/// <para>
/// 参数
/// </para>
/// </param>
public static string GetWebRequest(string serverUrl, string paramData, WebHeaderCollection header)
{
string requestUrl = serverUrl;
if (serverUrl.IndexOf('?') == -1 && paramData.IndexOf('?') == -1)
requestUrl += "?";
requestUrl += paramData;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl);
if (header != null)
request.Headers = header;
request.ContentType = "application/json";
request.Timeout = 30 * 1000;
request.Method = "GET";
string result = string.Empty;
using (var res = request.GetResponse() as HttpWebResponse)
{
if (res.StatusCode == HttpStatusCode.OK)
{
var reader = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
result = reader.ReadToEnd();
}
return result;
}
}
/// <summary>
/// WebRequest的 Post 请求
/// </summary>
/// <param name="serverUrl" type="string">
/// <para>
/// api地址(地址+方法)
/// </para>
/// </param>
/// <param name="postData" type="string">
/// <para>
/// 参数
/// </para>
/// </param>
public static string PostWebRequest(string serverUrl, string postData, WebHeaderCollection header)
{
var dataArray = Encoding.UTF8.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverUrl);
if (header != null)
request.Headers = header;
request.ContentLength = dataArray.Length;
//设置上传服务的数据格式
request.ContentType = "application/json";
request.Timeout = 30 * 1000;
request.Method = "POST";
//创建输入流
Stream dataStream;
try
{
dataStream = request.GetRequestStream();
}
catch (Exception)
{
return null;//连接服务器失败
}
//发送请求
dataStream.Write(dataArray, 0, dataArray.Length);
dataStream.Close();
//读取返回值
string result = string.Empty;
using (var res = request.GetResponse() as HttpWebResponse)
{
if (res.StatusCode == HttpStatusCode.OK)
{
var reader = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
result = reader.ReadToEnd();
}
return result;
}
}
}
封装的调用
namespace SOA.Common
{
public class ApiHelper
{
public static readonly ApiHelper Instance = new ApiHelper();
public string RequestApi(string method, string queryString, WebHeaderCollection header = null)
{
string result = WebRequestHelper.GetWebRequest(ConfigHelper.Config.ApiUrl + method, queryString, header);
return result;
}
public AjaxResult RequestApi<T>(string method, string queryString, WebHeaderCollection header = null)
{
var result = WebRequestHelper.GetWebRequest(ConfigHelper.Config.ApiUrl + method, queryString, header);
return SerializeResult<T>(result);
}
/// <summary>
/// 序列化结果
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="result"></param>
/// <returns></returns>
private AjaxResult SerializeResult<T>(string result)
{
AjaxResult resultModel = JsonConverter.FromJsonTo<AjaxResult>(result);
if (resultModel.Status == 0 && resultModel.Data != null && !string.IsNullOrEmpty(resultModel.Data.ToString()))
{
if (resultModel.Data.ToString().IndexOf("[") == 0 && StringHelper.IsJson(resultModel.Data.ToString()))
{
resultModel.Data = JsonConverter.FromJsonTo<List<T>>(resultModel.Data.ToString());
}
else if (StringHelper.IsJson(resultModel.Data.ToString()))
{
resultModel.Data = JsonConverter.FromJsonTo<T>(resultModel.Data.ToString());
}
}
return resultModel;
}
}
}
StringHelper.cs 帮助类
namespace SOA.Common
{
public class StringHelper
{
public static string AreaAttr(string defaultStr, int max = 0, string tipTitle = "", string tipid = "")
{
string text = "";
if (!string.IsNullOrWhiteSpace(defaultStr))
{
text = text + " tipmsg=\"" + defaultStr + "\" onfocus=\"utils.ContentKeyFocus(this)\" onblur=\"utils.ContentKeyBlur(this)\"";
text += " style=\"color:#999;\"";
}
if (max > 0)
{
string text2 = text;
text = string.Concat(new string[]
{
text2,
" onkeyup=\"utils.ContentKeyUpDown2(this,",
max.ToString(),
",'",
tipid,
"',0,'",
tipTitle,
"')\""
});
}
return text;
}
public static string InputAttr(string val, string defaultStr, int max = 0, string tipTitle = "", string tipid = "")
{
string text = "";
if (!string.IsNullOrWhiteSpace(val))
{
text = text + " value=\"" + val + "\"";
}
if (!string.IsNullOrWhiteSpace(defaultStr))
{
if (string.IsNullOrWhiteSpace(val))
{
text = text + " value=\"" + defaultStr + "\"";
}
text = text + " tipmsg=\"" + defaultStr + "\" onfocus=\"utils.ContentKeyFocus(this)\" onblur=\"utils.ContentKeyBlur(this)\"";
text += " style=\"color:#999;\"";
}
if (max > 0)
{
string text2 = text;
text = string.Concat(new string[]
{
text2,
" onkeyup=\"utils.ContentKeyUpDown2(this,",
max.ToString(),
",'",
tipid,
"',0,'",
tipTitle,
"')\""
});
}
return text;
}
public static string WapEncode(string source)
{
return (!string.IsNullOrEmpty(source)) ? source.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("‘", "'").Replace("\"", """).Replace("$", "$").Replace(" ", " ") : "";
}
public static string SubStr(string srcStr, int len)
{
string result;
if (len < 1)
{
result = string.Empty;
}
else
{
if (string.IsNullOrEmpty(srcStr))
{
result = srcStr;
}
else
{
int byteCount = System.Text.Encoding.Default.GetByteCount(srcStr);
if (byteCount <= len)
{
result = srcStr;
}
else
{
int num = 0;
int num2 = 0;
char[] array = srcStr.ToCharArray();
char[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
char c = array2[i];
int byteCount2 = System.Text.Encoding.Default.GetByteCount(array, num2, 1);
int num3 = num + byteCount2;
if (num3 > len)
{
result = srcStr.Substring(0, num2) + "...";
return result;
}
num = num3;
num2++;
}
result = srcStr;
}
}
}
return result;
}
public static string ReplaceIDS(string oldIds, bool isNoZero = true)
{
string result;
if (string.IsNullOrWhiteSpace(oldIds))
{
result = "";
}
else
{
string[] array = oldIds.Trim().Trim(new char[]
{
','
}).Split(new char[]
{
','
});
System.Collections.Generic.List<long> list = new System.Collections.Generic.List<long>();
string[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
string text = array2[i];
long num = TypeHelper.StrToInt64(text.Trim(), 0L);
if (!isNoZero || num != 0L)
{
if (!list.Contains(num))
{
list.Add(num);
}
}
}
string text2 = "";
foreach (long current in list)
{
text2 = text2 + "," + current.ToString();
}
result = text2.Trim(new char[]
{
','
});
}
return result;
}
public static string ReplaceStr2(string sourceStr)
{
string result;
if (string.IsNullOrWhiteSpace(sourceStr))
{
result = sourceStr;
}
else
{
result = sourceStr.Trim().Replace(" ", "").Replace("'", "").Replace("\"", "");
}
return result;
}
public static string Cut(string str, int len, System.Text.Encoding encoding)
{
string result;
if (string.IsNullOrEmpty(str))
{
result = str;
}
else
{
if (len <= 0)
{
result = string.Empty;
}
else
{
int byteCount = encoding.GetByteCount(str);
if (byteCount > len)
{
bool flag = byteCount == str.Length;
if (flag)
{
result = str.Substring(0, len);
return result;
}
int num = 0;
int num2 = 0;
char[] array = str.ToCharArray();
char[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
char c = array2[i];
int byteCount2 = encoding.GetByteCount(array, num2, 1);
int num3 = num + byteCount2;
if (num3 > len)
{
result = str.Substring(0, num2);
return result;
}
num = num3;
num2++;
}
}
result = str;
}
}
return result;
}
public static int GetChineseLength(string s)
{
int result;
if (string.IsNullOrEmpty(s))
{
result = 0;
}
else
{
result = System.Text.Encoding.GetEncoding("gb2312").GetByteCount(s);
}
return result;
}
public static int GetUTF8Length(string s)
{
int result;
if (string.IsNullOrEmpty(s))
{
result = 0;
}
else
{
result = System.Text.Encoding.UTF8.GetByteCount(s);
}
return result;
}
public static string StrFormat(string str)
{
string result;
if (str == null)
{
result = "";
}
else
{
str = str.Replace("\r\n", "<br />");
str = str.Replace("\n", "<br />");
result = str;
}
return result;
}
public static string EncodeHtml(string strHtml)
{
string result;
if (strHtml != "")
{
strHtml = strHtml.Replace(",", "&def");
strHtml = strHtml.Replace("'", "&dot");
strHtml = strHtml.Replace(";", "&dec");
result = strHtml;
}
else
{
result = "";
}
return result;
}
public static string HtmlDecode(string str)
{
return HttpUtility.HtmlDecode(str);
}
public static string HtmlEncode(string str)
{
return HttpUtility.HtmlEncode(str);
}
public static string UrlEncode(string str)
{
return HttpUtility.UrlEncode(str);
}
public static string UrlDecode(string str)
{
return HttpUtility.UrlDecode(str);
}
public static bool StrIsNullOrEmpty(string str)
{
return str == null || str.Trim() == string.Empty;
}
public static string CutString(string str, int startIndex, int length)
{
string result;
if (string.IsNullOrWhiteSpace(str))
{
result = "";
}
else
{
if (startIndex >= 0)
{
if (length < 0)
{
length *= -1;
if (startIndex - length < 0)
{
length = startIndex;
startIndex = 0;
}
else
{
startIndex -= length;
}
}
if (startIndex > str.Length)
{
result = "";
return result;
}
}
else
{
if (length < 0)
{
result = "";
return result;
}
if (length + startIndex <= 0)
{
result = "";
return result;
}
length += startIndex;
startIndex = 0;
}
if (str.Length - startIndex < length)
{
length = str.Length - startIndex;
}
result = str.Substring(startIndex, length);
}
return result;
}
public static string CutString(string str, int startIndex)
{
string result;
if (string.IsNullOrWhiteSpace(str))
{
result = "";
}
else
{
result = StringHelper.CutString(str, startIndex, str.Length);
}
return result;
}
public static string ToSqlInStr(System.Collections.Generic.List<int> ids)
{
string text = "";
if (ids != null && ids.Count > 0)
{
foreach (int current in ids)
{
text = text + current + ",";
}
}
text = text.Trim(",".ToCharArray());
return text;
}
public static string ToSqlInStr(System.Collections.Generic.List<long> ids)
{
string text = "";
if (ids != null && ids.Count > 0)
{
foreach (long current in ids)
{
text = text + current + ",";
}
}
text = text.Trim(",".ToCharArray());
return text;
}
public static string ToSqlInStr(System.Collections.Generic.List<string> ids)
{
string text = "";
if (ids != null && ids.Count > 0)
{
foreach (string current in ids)
{
text = text + "'" + current + "',";
}
}
text = text.Trim(",".ToCharArray());
return text;
}
public static string FilteSQLStr(string Str)
{
string result;
if (string.IsNullOrEmpty(Str))
{
result = "";
}
else
{
Str = Str.Replace("'", "");
Str = Str.Replace("\"", "");
Str = Str.Replace("&", "&");
Str = Str.Replace("<", "<");
Str = Str.Replace(">", ">");
Str = Str.Replace("delete", "");
Str = Str.Replace("update", "");
Str = Str.Replace("insert", "");
result = Str;
}
return result;
}
private static bool IsJsonStart(ref string json)
{
if (!string.IsNullOrEmpty(json))
{
json = json.Trim('\r', '\n', ' ');
if (json.Length > 1)
{
char s = json[0];
char e = json[json.Length - 1];
return (s == '{' && e == '}') || (s == '[' && e == ']');
}
}
return false;
}
internal static bool IsJson(string json)
{
int errIndex;
return IsJson(json, out errIndex);
}
internal static bool IsJson(string json, out int errIndex)
{
errIndex = 0;
if (IsJsonStart(ref json))
{
CharState cs = new CharState();
char c;
for (int i = 0; i < json.Length; i++)
{
c = json[i];
if (SetCharState(c, ref cs) && cs.childrenStart)//设置关键符号状态。
{
string item = json.Substring(i);
int err;
int length = GetValueLength(item, true, out err);
cs.childrenStart = false;
if (err > 0)
{
errIndex = i + err;
return false;
}
i = i + length - 1;
}
if (cs.isError)
{
errIndex = i;
return false;
}
}
return !cs.arrayStart && !cs.jsonStart;
}
return false;
}
/// <summary>
/// 获取值的长度(当Json值嵌套以"{"或"["开头时)
/// </summary>
private static int GetValueLength(string json, bool breakOnErr, out int errIndex)
{
errIndex = 0;
int len = 0;
if (!string.IsNullOrEmpty(json))
{
CharState cs = new CharState();
char c;
for (int i = 0; i < json.Length; i++)
{
c = json[i];
if (!SetCharState(c, ref cs))//设置关键符号状态。
{
if (!cs.jsonStart && !cs.arrayStart)//json结束,又不是数组,则退出。
{
break;
}
}
else if (cs.childrenStart)//正常字符,值状态下。
{
int length = GetValueLength(json.Substring(i), breakOnErr, out errIndex);//递归子值,返回一个长度。。。
cs.childrenStart = false;
cs.valueStart = 0;
//cs.state = 0;
i = i + length - 1;
}
if (breakOnErr && cs.isError)
{
errIndex = i;
return i;
}
if (!cs.jsonStart && !cs.arrayStart)//记录当前结束位置。
{
len = i + 1;//长度比索引+1
break;
}
}
}
return len;
}
/// <summary>
/// 字符状态
/// </summary>
private class CharState
{
internal bool jsonStart = false;//以 "{"开始了...
internal bool setDicValue = false;// 可以设置字典值了。
internal bool escapeChar = false;//以"\"转义符号开始了
/// <summary>
/// 数组开始【仅第一开头才算】,值嵌套的以【childrenStart】来标识。
/// </summary>
internal bool arrayStart = false;//以"[" 符号开始了
internal bool childrenStart = false;//子级嵌套开始了。
/// <summary>
/// 【0 初始状态,或 遇到“,”逗号】;【1 遇到“:”冒号】
/// </summary>
internal int state = 0;
/// <summary>
/// 【-1 取值结束】【0 未开始】【1 无引号开始】【2 单引号开始】【3 双引号开始】
/// </summary>
internal int keyStart = 0;
/// <summary>
/// 【-1 取值结束】【0 未开始】【1 无引号开始】【2 单引号开始】【3 双引号开始】
/// </summary>
internal int valueStart = 0;
internal bool isError = false;//是否语法错误。
internal void CheckIsError(char c)//只当成一级处理(因为GetLength会递归到每一个子项处理)
{
if (keyStart > 1 || valueStart > 1)
{
return;
}
//示例 ["aa",{"bbbb":123,"fff","ddd"}]
switch (c)
{
case '{'://[{ "[{A}]":[{"[{B}]":3,"m":"C"}]}]
isError = jsonStart && state == 0;//重复开始错误 同时不是值处理。
break;
case '}':
isError = !jsonStart || (keyStart != 0 && state == 0);//重复结束错误 或者 提前结束{"aa"}。正常的有{}
break;
case '[':
isError = arrayStart && state == 0;//重复开始错误
break;
case ']':
isError = !arrayStart || jsonStart;//重复开始错误 或者 Json 未结束
break;
case '"':
case '\'':
isError = !(jsonStart || arrayStart); //json 或数组开始。
if (!isError)
{
//重复开始 [""",{"" "}]
isError = (state == 0 && keyStart == -1) || (state == 1 && valueStart == -1);
}
if (!isError && arrayStart && !jsonStart && c == '\'')//['aa',{}]
{
isError = true;
}
break;
case ':':
isError = !jsonStart || state == 1;//重复出现。
break;
case ',':
isError = !(jsonStart || arrayStart); //json 或数组开始。
if (!isError)
{
if (jsonStart)
{
isError = state == 0 || (state == 1 && valueStart > 1);//重复出现。
}
else if (arrayStart)//["aa,] [,] [{},{}]
{
isError = keyStart == 0 && !setDicValue;
}
}
break;
case ' ':
case '\r':
case '\n'://[ "a",\r\n{} ]
case '\0':
case '\t':
break;
default: //值开头。。
isError = (!jsonStart && !arrayStart) || (state == 0 && keyStart == -1) || (valueStart == -1 && state == 1);//
break;
}
//if (isError)
//{
//}
}
}
/// <summary>
/// 设置字符状态(返回true则为关键词,返回false则当为普通字符处理)
/// </summary>
private static bool SetCharState(char c, ref CharState cs)
{
cs.CheckIsError(c);
switch (c)
{
case '{'://[{ "[{A}]":[{"[{B}]":3,"m":"C"}]}]
#region 大括号
if (cs.keyStart <= 0 && cs.valueStart <= 0)
{
cs.keyStart = 0;
cs.valueStart = 0;
if (cs.jsonStart && cs.state == 1)
{
cs.childrenStart = true;
}
else
{
cs.state = 0;
}
cs.jsonStart = true;//开始。
return true;
}
#endregion
break;
case '}':
#region 大括号结束
if (cs.keyStart <= 0 && cs.valueStart < 2 && cs.jsonStart)
{
cs.jsonStart = false;//正常结束。
cs.state = 0;
cs.keyStart = 0;
cs.valueStart = 0;
cs.setDicValue = true;
return true;
}
// cs.isError = !cs.jsonStart && cs.state == 0;
#endregion
break;
case '[':
#region 中括号开始
if (!cs.jsonStart)
{
cs.arrayStart = true;
return true;
}
else if (cs.jsonStart && cs.state == 1)
{
cs.childrenStart = true;
return true;
}
#endregion
break;
case ']':
#region 中括号结束
if (cs.arrayStart && !cs.jsonStart && cs.keyStart <= 2 && cs.valueStart <= 0)//[{},333]//这样结束。
{
cs.keyStart = 0;
cs.valueStart = 0;
cs.arrayStart = false;
return true;
}
#endregion
break;
case '"':
case '\'':
#region 引号
if (cs.jsonStart || cs.arrayStart)
{
if (cs.state == 0)//key阶段,有可能是数组["aa",{}]
{
if (cs.keyStart <= 0)
{
cs.keyStart = (c == '"' ? 3 : 2);
return true;
}
else if ((cs.keyStart == 2 && c == '\'') || (cs.keyStart == 3 && c == '"'))
{
if (!cs.escapeChar)
{
cs.keyStart = -1;
return true;
}
else
{
cs.escapeChar = false;
}
}
}
else if (cs.state == 1 && cs.jsonStart)//值阶段必须是Json开始了。
{
if (cs.valueStart <= 0)
{
cs.valueStart = (c == '"' ? 3 : 2);
return true;
}
else if ((cs.valueStart == 2 && c == '\'') || (cs.valueStart == 3 && c == '"'))
{
if (!cs.escapeChar)
{
cs.valueStart = -1;
return true;
}
else
{
cs.escapeChar = false;
}
}
}
}
#endregion
break;
case ':':
#region 冒号
if (cs.jsonStart && cs.keyStart < 2 && cs.valueStart < 2 && cs.state == 0)
{
if (cs.keyStart == 1)
{
cs.keyStart = -1;
}
cs.state = 1;
return true;
}
// cs.isError = !cs.jsonStart || (cs.keyStart < 2 && cs.valueStart < 2 && cs.state == 1);
#endregion
break;
case ',':
#region 逗号 //["aa",{aa:12,}]
if (cs.jsonStart)
{
if (cs.keyStart < 2 && cs.valueStart < 2 && cs.state == 1)
{
cs.state = 0;
cs.keyStart = 0;
cs.valueStart = 0;
//if (cs.valueStart == 1)
//{
// cs.valueStart = 0;
//}
cs.setDicValue = true;
return true;
}
}
else if (cs.arrayStart && cs.keyStart <= 2)
{
cs.keyStart = 0;
//if (cs.keyStart == 1)
//{
// cs.keyStart = -1;
//}
return true;
}
#endregion
break;
case ' ':
case '\r':
case '\n'://[ "a",\r\n{} ]
case '\0':
case '\t':
if (cs.keyStart <= 0 && cs.valueStart <= 0) //cs.jsonStart &&
{
return true;//跳过空格。
}
break;
default: //值开头。。
if (c == '\\') //转义符号
{
if (cs.escapeChar)
{
cs.escapeChar = false;
}
else
{
cs.escapeChar = true;
return true;
}
}
else
{
cs.escapeChar = false;
}
if (cs.jsonStart || cs.arrayStart) // Json 或数组开始了。
{
if (cs.keyStart <= 0 && cs.state == 0)
{
cs.keyStart = 1;//无引号的
}
else if (cs.valueStart <= 0 && cs.state == 1 && cs.jsonStart)//只有Json开始才有值。
{
cs.valueStart = 1;//无引号的
}
}
break;
}
return false;
}
}
}
WebApi的调用-2.后台调用的更多相关文章
- c#后台调用API
前两周赶上项目第一个版本上线,着实忙了一把,毕竟只有两个人负责.如今已完结,总算喘了一口气,现在任务就是写API.测API,许久之前写过JS前台调用 项目API,也写过后台调用开放的手机号归属地查询, ...
- 使用OAuth、Identity创建WebApi认证接口供客户端调用
前言 现在的web app基本上都是前后端分离,之前接触的大部分应用场景最终产品都是部署在同一个站点下,那么随着WebApi(Restful api)的发展前后端实现的完全分离,前端不在后端框架的页面 ...
- 获取ip ,百度地图坐标点 和 在 后台调用 url()
protected void getip() { string ips = HttpContext.Current.Request.UserHostA ...
- 由ASP.NET所谓前台调用后台、后台调用前台想到HTTP——实践篇(二)
在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——理论篇中描述了一下ASP.NET新手的三个问题及相关的HTTP协议内容,在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP—— ...
- 由ASP.NET所谓前台调用后台、后台调用前台想到HTTP——理论篇
工作两年多了,我会经常尝试给公司小伙伴儿们解决一些问题,几个月下来我发现初入公司的小朋友最爱问的问题就三个 1. 我想前台调用后台的XXX方法怎么弄啊? 2. 我想后台调用前台的XXX JavaScr ...
- Javascript调用C#后台方法及JSon解析
Javascript调用C#后台方法及JSon解析 如何使用Ajax 调用C# 后台方法. 本文目录 如何使用Ajax 调用C# 后台方法. 1.后台(.cs)测试方法 2.前台调用(javasc ...
- WebService – 3.后台调用WebService,根级别上的数据无效
1.因为我的webservice返回的是json, 2.ajax传递跨域不安全, 3.contentType: "application/json; charset=utf-8", ...
- Http下的各种操作类.WebApi系列~通过HttpClient来调用Web Api接口
1.WebApi系列~通过HttpClient来调用Web Api接口 http://www.cnblogs.com/lori/p/4045413.html HttpClient使用详解(java版本 ...
- js前台与后台数据交互-后台调前台(后台调用、注册客户端脚本)
转自:http://blog.csdn.net/wang379275614/article/details/17049721 客户端脚本一般都在前台,这里讲的是(1)在后台调用前台定义的脚本(2)在后 ...
随机推荐
- JAVA记录-redis缓存机制介绍(三)
Redis 事务 Redis 事务可以一次执行多个命令, 并且带有以下两个重要的保证: 事务是一个单独的隔离操作:事务中的所有命令都会序列化.按顺序地执行.事务在执行的过程中,不会被其他客户端发送来的 ...
- 直接用<img> 的src属性显示base64转码后的字符串成图片【原】
直接用<img> 的src属性显示base64转码后的字符串成图片 <img src="data:image/gif;base64,base64转码后的字符串" ...
- Study 3 —— 表格
表格基本格式: <table> <tr> <td></td> <td></td> </tr> <tr> ...
- CircleList-使用UGUI实现的圆形列表
CircleList CircleList是一个通过UGUI实现的圆形列表,通过缩放.平移和层级的改变模拟一个3D的圆形列表. 效果 添加与旋转 间距调整 椭圆形的旋转 参数 CenterX: 椭圆圆 ...
- Linux 命令详解(十一)Shell 解析 json命令jq详解
前言 在自动化部署中涉及到shell脚本需要动态读取很多配置文件,最好是json格式. 更多jq信息: http://stedolan.github.io/jq/manual/ 一.根据key获取va ...
- DOM-Document对象
一. 整体介绍 这里介绍DOM对象中的Document对象. 何为Document对象?每个载入浏览器的HTML文档都会成为Document对象,Document对象可以帮助我们对所有的HTML ...
- vue项目首次加载过慢
vue项目优化 浅谈 Vue 项目优化 关于vue在app首次加载缓慢的解决办法 nginx开启缓存 在http部分加入 #要想开启nginx的缓存功能,需要添加此处的两行内容! #设置Web缓存区名 ...
- python执行centos命令
import os improt sys import re import commands a = commands.getoutput("ls -al /") print a
- 使用 Parallel LINQ 进行数据分页
a) 第一种[耗时11~18s],这种查询方式并不是很优化,但是目前也没有想到更好的方式,除了创建一张中间表,是不是可以使用[全文索引]? SELECT * FROM ( SELECT ROW_ ...
- POJ2421 Constructing Roads【最小生成树】
题意: 有N个点,有些点已经连接了,然后求出所有点的连接的最短路径是多少. 思路: 最小生成树的变形,有的点已经连接了,就直接把他们的权值赋为0,一样的就做最小生成树. 代码: prime: #inc ...