有没有办法在winforms c提交url后获取浏览器文本# [英] Is there a way to get browser text after url submit in winforms c#

查看:62
本文介绍了有没有办法在winforms c提交url后获取浏览器文本#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



这可能听起来像一个愚蠢的问题,但有一种方法可以让我在使用提交网址后看到浏览器显示的内容Winforms C#?



基本上使用C#发送以下URL并发送短信:



< pre lang =c#> string url = http ://api.panaceamobile.com/json?action = message_send& username = + username + & password = +密码+ & to = +收件人+
& text = + message + ;





如果您粘贴此链接任何浏览器,如果客户的帐户,它将显示以下内容余额为0:



{状态: - 64,消息:信用不足}



这一切都很精彩。但是我需要一种方法来将浏览器中显示的上述文本发送回我的应用程序并将其存储在变量中。



这可能吗?

解决方案

我建​​议你不要使用浏览器制作HTTP请求,但请使用 HttpWebRequest [ ^ ]。然后很容易直接获得响应,没有浏览器技巧。



Codeproject - 文章显示:

HUTpWebRequest/Response in a Nutshell - Part 1 [ ^ ]



Google搜索更多文章:

https://www.google.com/search?q=c%23+httpclient+codeproject&ie=utf-8& oe = utf-8#q = c%23 + httpwebrequest + codeproject [ ^ ]


我想过我自己解决了解决方案并将其发布对于将来需要它的人来说。



我刚刚将以下内容添加到我的代码中。



< pre lang =c#> WebClient returnValue = new WebClient();
string value = returnValue.DownloadString(url);





然后值变量有浏览器文本。



谢谢!


Hi all,

This might sound like a dumb question, but is there a way for me to see what the browser is displaying after I submit a url using Winforms C#?

Basically the following URL is sent using C# and an sms is sent:

string url = "http://api.panaceamobile.com/json?action=message_send&username=" + username + "&password=" + password + "&to=" + recipient +
                         "&text=" + message + "";



If you paste this link in any browser it will display the following if the client's account has a 0 balance:

{"status":-64,"message":"Out of credit"}

This is all wonderful. But I need a way to get the above text that is displayed in the browser to be sent back to my application and store it in a variable.

Is this possible?

解决方案

I would suggest you don't use the browser to make the HTTP-request but do it yourself with HttpWebRequest[^]. Then it's easy to get the response directly, without "browser tricks".

A Codeproject-Article showing this:
HttpWebRequest/Response in a Nutshell - Part 1[^]

Google-search for more articles:
https://www.google.com/search?q=c%23+httpclient+codeproject&ie=utf-8&oe=utf-8#q=c%23+httpwebrequest+codeproject[^]


I figured out the solution myself and will post it here for anyone needing it in future.

I just added the following to my code.

WebClient returnValue = new WebClient();
            string value = returnValue.DownloadString(url);



And then the value variable has the browser text.

Thanks!


这篇关于有没有办法在winforms c提交url后获取浏览器文本#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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