如何将数据发布到其他网站。 [英] How to post data to other websites.

查看:90
本文介绍了如何将数据发布到其他网站。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys。

我有一个网站,用户必须在其他网站上填写数据才能完成整个过程。我希望用户可以使用我的网站提交他们的所有数据,而无需访问其他网站。我一直在寻找它。我发现它可以通过http请求实现,但我不明白。请提供其他教程的链接..

Hello Guys.
I have a website in which user have to fill data on the other site to complete the process. I want that the users can submit all their data with my site without having to visit other site. I have been searching it for a lot. All i found that it can be achieved by http requests, but i didn't understand. Please provide me links to other tutorials..

推荐答案

您可以使用WebClient或HTMLAgility。



With WebClient你可以使用这样的东西。



you can use WebClient or HTMLAgility.

With WebClient you can use somthing like this.

public string SendPost(string url, string postData)
{
    string webpageContent = string.Empty;

    try
    {
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);

        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
        webRequest.Method = "POST";
        webRequest.ContentType = "application/x-www-form-urlencoded";
        webRequest.ContentLength = byteArray.Length;

        using (Stream webpageStream = webRequest.GetRequestStream())
        {
            webpageStream.Write(byteArray, 0, byteArray.Length);
        }

        using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
        {
            using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
            {
                webpageContent = reader.ReadToEnd();
            }
        }
    }
    catch (Exception ex)
    {
        //throw or return an appropriate response/exception
    }

    return webpageContent;
}


这篇关于如何将数据发布到其他网站。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆