asp.net后台代码:

string urlTemp = Request["url"].ToString();
string callbackFunName = Request["callbackparam"];

jquery代码:

function getMsg() {
    var urlTemp = encodeURI($("#url").val());
    $.ajax({
        url: "Default.aspx",
        type: "POST",
        cache: false,
        data: "url=" + urlTemp,
        dataType: "jsonp",
        jsonp: "callbackparam",//服务端用于接收callback调用的function名的参数
        jsonpCallback: "success_jsonpCallback",//callback的function名称 
        success: function (result) {
            //log(result);
            if (result.status == 0) {
                alert(result.info);
                //$("#submit").attr("value", result.info);
                //$("#submit").attr("disabled", "disabled");
                return;
            }
        },
        error: function () {
            alert('fail');
        }
    });
}

_ueditor_page_break_tag_

对于要调用其它网站的post数据,我们不可能控制到别人的后台,就需要用c#在后台模拟post提交,得到结果

string url = "http://u.duoduo123.com/index.php?g=alliance&m=goods&a=taodianjian&lanmu=1";
string postString = "url=" + urlTemp + "&lanmu=1" + "&id=";
byte[] postData = Encoding.UTF8.GetBytes(postString);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";
//request.CookieContainer = cookieContainer;
request.ContentLength = postData.Length;
//request.AllowAutoRedirect = false;
//cookieheader = request.CookieContainer.GetCookieHeader(new Uri(URI));
//List<Cookie> CookieList = GetAllCookies(cookieContainer);
// 提交请求数据 
System.IO.Stream outputStream = request.GetRequestStream();
outputStream.Write(postData, 0, postData.Length);
outputStream.Close();
//接收返回的页面,必须的,不能省略 
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, Encoding.GetEncoding("GB2312"));
string srcString = reader.ReadToEnd();
Response.Write(callbackFunName + "(" + srcString + ")");

http://zhidao.baidu.com/question/586476617.html

http://www.cnblogs.com/chopper/archive/2012/03/24/2403945.html 

最后修改:2014 年 12 月 03 日
如果觉得我的文章对你有用,请随意赞赏