Ajax----------跨站点取数据
来源:互联网 发布:ewbwin10仿真软件下载 编辑:程序博客网 时间:2024/06/05 10:28
using System.Net;
using System.IO;
using System.Text;
public string getJSON(string param)
{
//param = "{/ "modules/ ":[{/ "id/ ":1,/ "name/ ":/ "xxxx/ ",/ "method/ ":/ "get/ ",/ "post_url/ ":
/ "http://www.xxx.net/xx_xx.php?module=xx&wop=post/ ",/ "param/ ":/ "w_xxx_/ ",/ "args/ ":{/ "view/ ":/ "default/ ",/ "position/ ":/ "center/ "},/ "params/ ":[]}],/ "global/ ":{/ "user/ ":{/ "user_id/ ":xxx,/ "email/ ":/ "xx.xxx@xx.xx/ ",/ "first_name/ ":/ "xxx/ ",/ "last_name/ ":/ "xxx/ "}}} ";
byte[] bs = Encoding.ASCII.GetBytes(param);
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create( "http://www.xxx.net/xxx_xxx.php ");
req.Method = "POST ";
//req.Connection = "close ";
req.ContentType = "application/x-javascript ";
req.ContentLength = bs.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(bs, 0, bs.Length);
}
string str = string.Empty;
using (WebResponse wr = req.GetResponse())
{
Stream ReceiveStream = wr.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding( "utf-8 ");
StreamReader readStream = new StreamReader(ReceiveStream, encode);
Char[] read = new Char[256];
int count = readStream.Read(read, 0, 256);
while (count > 0)
{
// Dump the 256 characters on a string and display the string onto the console.
str += new String(read, 0, count);
count = readStream.Read(read, 0, 256);
}
readStream.Close();
}
return str;
}
然后另外一个页面再使用AJAX的方法或者这个页面的数据
using System.IO;
using System.Text;
public string getJSON(string param)
{
//param = "{/ "modules/ ":[{/ "id/ ":1,/ "name/ ":/ "xxxx/ ",/ "method/ ":/ "get/ ",/ "post_url/ ":
/ "http://www.xxx.net/xx_xx.php?module=xx&wop=post/ ",/ "param/ ":/ "w_xxx_/ ",/ "args/ ":{/ "view/ ":/ "default/ ",/ "position/ ":/ "center/ "},/ "params/ ":[]}],/ "global/ ":{/ "user/ ":{/ "user_id/ ":xxx,/ "email/ ":/ "xx.xxx@xx.xx/ ",/ "first_name/ ":/ "xxx/ ",/ "last_name/ ":/ "xxx/ "}}} ";
byte[] bs = Encoding.ASCII.GetBytes(param);
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create( "http://www.xxx.net/xxx_xxx.php ");
req.Method = "POST ";
//req.Connection = "close ";
req.ContentType = "application/x-javascript ";
req.ContentLength = bs.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(bs, 0, bs.Length);
}
string str = string.Empty;
using (WebResponse wr = req.GetResponse())
{
Stream ReceiveStream = wr.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding( "utf-8 ");
StreamReader readStream = new StreamReader(ReceiveStream, encode);
Char[] read = new Char[256];
int count = readStream.Read(read, 0, 256);
while (count > 0)
{
// Dump the 256 characters on a string and display the string onto the console.
str += new String(read, 0, count);
count = readStream.Read(read, 0, 256);
}
readStream.Close();
}
return str;
}
然后另外一个页面再使用AJAX的方法或者这个页面的数据
- Ajax----------跨站点取数据
- jquery $.ajax()取xml数据
- asp.net web api 解决ajax跨站点post请求提交 json 数据问题
- .net web api 解决ajax跨站点post请求提交 json 数据问题
- asp.net web api 解决ajax跨站点post请求提交 json 数据问题
- Ajax多次取数据后出现乱码
- JS Ajax取.NET 数据中文问题
- Ajax异步取数据,下拉框联动
- Ajax异步从后台取Json数据
- Ajax定时从服务器取数据
- Ajax拿取html格式数据
- Ajax拿取JSON格式的数据
- 从Ajax的Web站点中提取数据
- phpcms 取站点名
- AJAX For.NET 取数据以及数据查询实例,
- 聚合数据全国天气预报--ajax 通过城市名取数据
- AJAX异步取缓存数据(先挖个坑,留着以后再用)
- ajax+jsp异步无刷新从DB取数据
- 开始→运行→输入的命令集锦
- 学习VB中
- CORBA Introduction
- 招考城管面试问答
- mvrlib开发日志Start
- Ajax----------跨站点取数据
- MVC模型中的Observer模式
- 堆栈和堆的区别(ZZ)
- 什么是联属网络营销(Affiliate Marketing)?
- 让VS 2008支持Subversion
- 内码转换
- VB静态链表
- Delphi中webbrowser 不能复制粘贴
- mvrlib开发日志 2