如何调用接口,请帮帮忙 代码贴下http://www.cnblogs.com/hfliyi/archive/2012/08/21/2649892.html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string url = "http://api.jiekou.com/?jd=" + dr["lon"].ToString() + "&wd=" + dr["lat"].ToString(); WebClient MyWebClient = new WebClient(); MyWebClient.Credentials = CredentialCache.DefaultCredentials; Byte[] pageData = MyWebClient.DownloadData(url); string pageHtmlT = Encoding.UTF8.GetString(pageData); string postData = "jd="+ Sina.APP_ID +"&wd="+ Sina.APP_KEY ; byte[] bytes = Encoding.UTF8.GetBytes(postData); WebClient client = new WebClient(); client.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); client.Headers.Add("ContentLength", postData.Length.ToString()); byte[] responseData = client.UploadData("https://api.weibo.com/oauth2/access_token", "POST", bytes); 不是这样做的? 首先接口好像前台页面不需要放什么东西吧?然后地址后面是接 xxx.aspx?id=xxx&pwd=xxx 少了个问号 是不是 因为我前端写了js的代码,导致一定要在浏览器里才能运行,如果是程序代码去调用,就无法打开浏览器就不能运行js代码了,请大神指教 反正是要跟数据库交互,你就没必要纠结js了直接在后台的aspx.cs的page_load里写代码,获取url参数,执行数据库插入,不好吗 /// <summary> /// 用HttpWebRequest取得网页源码 /// 对于带BOM的网页很有效,不管是什么编码都能正确识别 /// </summary> /// <param name="url">网页地址" </param> /// <returns>返回网页源文件</returns> public static string GetHtmlSource(this string url) { //处理内容 string html = ""; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Accept = "*/*"; //接受任意文件 request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)"; // 模拟使用IE在浏览 request.AllowAutoRedirect = true;//是否允许302 //request.CookieContainer = new CookieContainer();//cookie容器, request.Referer = url; //当前页面的引用 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.Default); html = reader.ReadToEnd(); stream.Close(); return html; } ASP.NET中@@identity 请教:DataTable批量更新问题 C#与javascript混用 DataList控件的选择模板SelectedItemTemplate有什么用 |M| 再开一贴求VS2005 Altas中 实现alert('')功能的办法 可以把默认的调试浏览器改成别的么?就是不用IE? 如何判断数据为空? 求一书配套源码:Beginning ASP.NET Database using C# ASP.net localhost 端口设置 asp.net调试问题 使用nlog只记录各模块的增删改 NTKO如何一个页面添加多个?
WebClient MyWebClient = new WebClient();
MyWebClient.Credentials = CredentialCache.DefaultCredentials;
Byte[] pageData = MyWebClient.DownloadData(url);
string pageHtmlT = Encoding.UTF8.GetString(pageData);
byte[] bytes = Encoding.UTF8.GetBytes(postData);
WebClient client = new WebClient();
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.Headers.Add("ContentLength", postData.Length.ToString());
byte[] responseData = client.UploadData("https://api.weibo.com/oauth2/access_token", "POST", bytes);
不是这样做的?
直接在后台的aspx.cs的page_load里写代码,获取url参数,执行数据库插入,不好吗
/// <summary>
/// 用HttpWebRequest取得网页源码
/// 对于带BOM的网页很有效,不管是什么编码都能正确识别
/// </summary>
/// <param name="url">网页地址" </param>
/// <returns>返回网页源文件</returns>
public static string GetHtmlSource(this string url)
{
//处理内容
string html = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Accept = "*/*"; //接受任意文件
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)"; // 模拟使用IE在浏览
request.AllowAutoRedirect = true;//是否允许302
//request.CookieContainer = new CookieContainer();//cookie容器,
request.Referer = url; //当前页面的引用 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.Default);
html = reader.ReadToEnd();
stream.Close(); return html;
}