标签: httpwebresponse

如何监控网站的变化?

所以我已经为此工作了一个月,但我在网上什么也没找到,所以我认为可能每分钟检查一次网站源代码的变化,但似乎它的源代码每秒都在变化,所以有没有我的编码有问题还是有其他方法可以监控网站的变化?

这是我的代码:

private void Startbtn_Click(object sender, EventArgs e)
   {

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");                            
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader source = new StreamReader(response.GetResponseStream());
richTextBox1.Text = source.ReadToEnd();
timer1.Start();
timer1.Interval = 60000;

     }

private void timer1_Tick(object sender, EventArgs e)
    {

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader source2 = new StreamReader(response.GetResponseStream());
        RichTextBox checker = new RichTextBox();
        checker.Text = source2.ReadToEnd();
        if (richTextBox1.Text == "")
        {
            richTextBox1.Text = checker.Text;

        }
        else
        {


            if (richTextBox1.Text != checker.Text)
            {
                MessageBox.Show("somthing changed");
                richTextBox1.Text = checker.Text;
            } …
Run Code Online (Sandbox Code Playgroud)

c# monitoring httpwebrequest httpwebresponse web

5
推荐指数
1
解决办法
6111
查看次数

400 错误请求 | 从 ASP.NET Web API 接收自定义错误消息或模型

我们有一个由第三方公开的 Web API,我们对此没有任何控制权。看起来他们正在包装自定义错误消息模型以返回 400(错误请求))。

\n\n

使用 Postman 时我们得到自定义错误消息模型

\n\n
{\n    "Message":\xc2\xa0"Site Name Exists",\n    "ErrorId":\xc2\xa0"<some-guid>",\n    "ErrorCode":\xc2\xa0400,\n    "GeneratedTime":\xc2\xa0"<some-datatime>",\n    "RequestedUri":\xc2\xa0"origin-api-uri"\n} \n
Run Code Online (Sandbox Code Playgroud)\n\n

我们尝试使用HttpWebResponseWebResponse从 API 获取响应,但它在 上抛出异常并显示 400 代码httpWebRequest.GetResponse()。它没有给我们预期的响应,就像我们在 Postman 中得到的那样,但它说 400(错误请求)并带有默认错误消息“远程服务器返回错误”。

\n\n

我们希望以邮差身份获取原始错误消息。有什么想法吗?

\n

c# httpwebrequest httpwebresponse asp.net-web-api

5
推荐指数
1
解决办法
9270
查看次数

HttpWebRequest和HttpWebResponse:维护连续查询的登录请求状态

我有一些链接在一起的HttpWebRequests和HttpWebResponses,也使用CookieContainer.

该代码模拟用户通过三个不同的"我同意"页面设置cookie信息,使用用户名和密码登录第四个,并在第五个上执行POST(搜索),将响应作为字符串返回.

有没有办法可以将HttpWebRequest对象维护为"登录",以避免每次用户执行搜索时都经过这些步骤?

我可以将其设置为静态,如果它的null或缺少cookie信息,它可以运行所有步骤,否则只是做用户需要的帖子?对此有什么好的模式?

c# asp.net state httpwebrequest httpwebresponse

4
推荐指数
1
解决办法
1929
查看次数

非常慢的WebResponse触发TimeOut

我在C#中有一个函数,它通过从路由器页面检索64b XML来获取Internet的状态

public bool isOn()
        {
            HttpWebRequest hwebRequest = (HttpWebRequest)WebRequest.Create("http://" + this.routerIp + "/top_conn.xml");
            hwebRequest.Timeout = 500;
            HttpWebResponse hWebResponse = (HttpWebResponse)hwebRequest.GetResponse();
            XmlTextReader oXmlReader = new XmlTextReader(hWebResponse.GetResponseStream());       
            string value;
            while (oXmlReader.Read())
            {
                value = oXmlReader.Value;
                if (value.Trim() != ""){
                    return !value.Substring(value.IndexOf("=") + 1, 1).Equals("0");
                }
            }
            return false;

        }
Run Code Online (Sandbox Code Playgroud)

使用Mozilla Firefox 3.5和FireBug插件我猜测它通常需要30ms来检索页面,但是在非常大的500ms限制下它仍然经常达到它.如何显着提高性能?

提前致谢

c# xml httpwebrequest httpwebresponse

4
推荐指数
1
解决办法
4696
查看次数

HttpWebResponse返回404错误

如何让Httpwebresponse忽略404错误并继续使用它?它比在输入中查找异常更容易,因为在发生这种情况时非常罕见.

c# httpwebresponse http-status-code-404

4
推荐指数
2
解决办法
2万
查看次数

VB.NET使用WebRequest检查URI是否有效

寻找确定VB.NET中是否存在URI而不下载实际内容的最佳方法.System.IO.FileExists/ My.Computer.FileSystem.FileExists可以在本地使用来确定文件是否存在,是否存在Web的等价物?

目前我正在使用a HttpWebRequest来检查URI的存在性ResponseStream.如果目标确实存在,则填充流,如果不存在,则抛出异常.该功能正在扩展,以检查PDF文件(通常为5MB +),图像等,实际将内容填充到流中将浪费时间/带宽.

在"成功"(目标确实存在)的情况下,我不希望下载文件或页面,只是最终得到一个布尔值,该布尔值指示此URI末尾是否存在某些内容.

vb.net httpwebresponse

4
推荐指数
2
解决办法
1万
查看次数

尝试使用HttpWebRequest获取身份验证cookie

我必须从安全站点刮一张桌子,我无法登录页面并检索身份验证令牌和任何其他相关的cookie.我在这里做错了吗?

public NameValueCollection LoginToDatrose()
{
    var loginUriBuilder = new UriBuilder();
    loginUriBuilder.Host = DatroseHostName;
    loginUriBuilder.Path = BuildURIPath(DatroseBasePath, LOGIN_PAGE);
    loginUriBuilder.Scheme = "https";

    var boundary = Guid.NewGuid().ToString();
    var postData = new NameValueCollection();
    postData.Add("LoginName", DatroseUserName);
    postData.Add("Password", DatrosePassword);

    var data = Encoding.ASCII.GetBytes(postData.ToQueryString(false));
    var request = WebRequest.Create(loginUriBuilder.Uri) as HttpWebRequest;
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = data.Length;
    using (var d = request.GetRequestStream())
    {
        d.Write(data, 0, data.Length);
    }

    var response = request.GetResponse() as HttpWebResponse;
    var responseCookies = new NameValueCollection();
    foreach (var nvp in response.Cookies.OfType<Cookie>())
    {
        responseCookies.Add(nvp.Name, …
Run Code Online (Sandbox Code Playgroud)

c# screen-scraping webclient httpwebrequest httpwebresponse

4
推荐指数
1
解决办法
1万
查看次数

从HttpWebResponse获取重定向的URL的集合

我试图找回从代表所采取的路径URL列表URL XURL Y这里X可能会被重定向几次.

例如:

http://www.example.com/foo

这将重定向到:

http://www.example.com/bar

然后重定向到:

http://www.example.com/foobar

有没有办法从响应对象中获取此重定向路径作为字符串: http://www.example.com/foo > http://www.example.com/bar > http://www.example.com/foobar

我可以通过ResponseUrieg 获取最终的URL

public static string GetRedirectPath(string url)
{
    StringBuilder sb = new StringBuilder();
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    using (var response = (HttpWebResponse)request.GetResponse())
    {
        sb.Append(response.ResponseUri);
    }
    return sb.ToString();
}
Run Code Online (Sandbox Code Playgroud)

但这显然会在两者之间跳过URL.似乎没有一种简单的方法(或根本没有方法?)来获得完整的途径?

c# url redirect httpwebresponse

4
推荐指数
1
解决办法
6084
查看次数

HttpWebResponse在循环运行时卡住了

我构建此方法(c#)以便从URL接收HTTP响应状态代码.我运行这种方法的时候它的工作正常,但是当我在一个循环中运行它时,它第三次卡住了.任何线索?

 public static string isAlive(string url)
    {
        Console.WriteLine("start: Is Alive Test");
        WebRequest request = WebRequest.Create(url);
        try
        {
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            return Convert.ToString((int)response.StatusCode);
        }
        catch(WebException ex)
        {
            HttpWebResponse res  = (HttpWebResponse)ex.Response;
            return Convert.ToString((int)res.StatusCode);
        }
    }
Run Code Online (Sandbox Code Playgroud)

循环

        for (int i = 0; i < 5; i++)
        {
            string a = isAlive("https://www.yahoo.com/");
            Console.WriteLine(a);
        }
Run Code Online (Sandbox Code Playgroud)

.net c# webrequest httpwebresponse getresponse

4
推荐指数
1
解决办法
2006
查看次数

PayPal API Http调用问题

我已经为用户集成了一个选项,通过PayPal在我正在创建的网上商店进行在线购物.当我开始收到此错误时突然出现问题:

You must write ContentLength bytes to the request stream before calling [Begin]GetResponse. 
Run Code Online (Sandbox Code Playgroud)

Http调用的代码如下:

   public string HttpCall(string NvpRequest)
        {
            string url = pEndPointURL;

            string strPost = NvpRequest + "&" + buildCredentialsNVPString();
            strPost = strPost + "&BUTTONSOURCE=" + HttpUtility.UrlEncode(BNCode);

            HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
            objRequest.Timeout = Timeout;
            objRequest.Method = "POST";
            objRequest.ContentLength = strPost.Length;

            try
            {
                using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
                {
                    myWriter.Write(strPost.ToString());
                }
            }
            catch (Exception e)
            {

            }

            //Retrieve the Response returned from the NVP API call to PayPal. 
            HttpWebResponse …
Run Code Online (Sandbox Code Playgroud)

c# asp.net paypal httpwebrequest httpwebresponse

4
推荐指数
1
解决办法
2745
查看次数