本文整理汇总了C#中System.Net.WebClient.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.Contains方法的具体用法?C# WebClient.Contains怎么用?C# WebClient.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了WebClient.Contains方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Infected
/// <summary>
/// Check if the webpage is realy infected
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public bool Infected(string url)
{
string html = "";
try
{
html = new WebClient().DownloadString(url + " '");
}
catch
{
// ignored
}
return html.Contains("You have an error in your SQL syntax;");
}
示例2: CanAlterHelpPage
public void CanAlterHelpPage()
{
host.AddMetadataMessageInspector(new EasyMetadataInterceptor()
{
Html = doc =>
{
var body = doc.Descendants().Where((n) => n.Name.LocalName == "BODY").FirstOrDefault();
body.AddFirst(new XElement(XName.Get("p"), marker));
return doc;
},
});
host.Open();
var helppage = new WebClient().DownloadString(uri);
Assert.IsTrue(helppage.Contains("<p>" + marker + "</p>"));
}
示例3: CanAlterWsdl
public void CanAlterWsdl()
{
host.AddMetadataMessageInspector(new EasyMetadataInterceptor()
{
Wsdl = doc =>
{
foreach (var port in doc.Descendants().Where((n) => n.Name.LocalName == "port"))
{
port.AddFirst(new XElement(XName.Get("wsdl"), marker));
}
return doc;
},
});
host.Open();
var wsdl = new WebClient().DownloadString(uri + "?WSDL");
Assert.IsTrue(wsdl.Contains("<wsdl>" + marker + "</wsdl>"));
}
示例4: PublishPrivateTest
public void PublishPrivateTest()
{
// arrange
var targetSteam = "test";
var handle = Guid.NewGuid().ToString();
var message = "DOTNET_UT_PublishPrivateTest()";
//act
_tambur.Publish(targetSteam, CreateHandleJsonString(handle, message));
// assert
var results = new WebClient().DownloadString("http://wsbot.tambur.io/results?handle=" + handle);
Assert.IsTrue(results.Contains(handle));
Assert.IsTrue(results.Contains(message));
// inform
Debug.WriteLine("wsbot responding with " + results);
// FIXME: To be continued ==> see https://github.com/tamburio/java-tambur/blob/master/src/test/java/io/tambur/TamburPublishTest.java
}
示例5: TestHttpWeb
public void TestHttpWeb()
{
foreach (var s in _serviceManager.AllServers)
{
Console.WriteLine(s.Port);
var protocol = s.UseHttps ? "https" : "http";
var html = new WebClient().DownloadString(string.Format("{1}://localhost:{0}/", s.Port, protocol));
Assert.IsTrue(html.Contains("Hello World"));
}
}
示例6: IsAuthenticated
public bool IsAuthenticated()
{
if (ServerSettings.OnlineMode)
{
try
{
var uri = new Uri(
string.Format(
"http://session.minecraft.net/game/checkserver.jsp?user={0}&serverId={1}",
Username,
PacketCryptography.JavaHexDigest(Encoding.UTF8.GetBytes("")
.Concat(Wrapper.SharedKey)
.Concat(PacketCryptography.PublicKeyToAsn1(Globals.ServerKey))
.ToArray())
));
var authenticated = new WebClient().DownloadString(uri);
if (authenticated.Contains("NO"))
{
ConsoleFunctions.WriteInfoLine("Response: " + authenticated);
return false;
}
}
catch
{
return false;
}
return true;
}
return true;
}
示例7: Main
//.........这里部分代码省略.........
try
{
// a running applicaion should know when it can reload itself
// when all running tasks are complete and no new tasks are to be taken.
var videoUrl = link;
bool isYoutubeUrl = DownloadUrlResolver.TryNormalizeYoutubeUrl(videoUrl, out videoUrl);
//Console.WriteLine(new { sw.ElapsedMilliseconds, px, videoUrl });
// wont help
//var y = DownloadUrlResolver.GetDownloadUrls(link);
//var j = DownloadUrlResolver.LoadJson(videoUrl);
var c = new WebClient().DownloadString(videoUrl);
// "Kryon - Timing o..." The YouTube account associated with this video has been terminated due to multiple third-party notifications of copyright infringement.
// <link itemprop="url" href="http://www.youtube.com/user/melania1172">
// { videoUrl = http://youtube.com/watch?v=li0E4_7ap3g, ch_name = , userurl = https://youtube.com/user/ }
//{ url = http://youtube.com/watch?v=li0E4_7ap3g }
//{ err = YoutubeExtractor.YoutubeParseException: Could not parse the Youtube page for URL http://youtube.com/watch?v=li0E4_7ap3g
// <h1 id="unavailable-message" class="message">
// 'IS_UNAVAILABLE_PAGE': false,
var unavailable =
!c.Contains("'IS_UNAVAILABLE_PAGE': false") ?
c.SkipUntilOrEmpty("<h1 id=\"unavailable-message\" class=\"message\">").TakeUntilOrEmpty("<").Trim() : "";
if (unavailable != "")
{
// 180?
countunavailable++;
Console.Title = new { countunavailable }.ToString();
Console.WriteLine(new { videoUrl, unavailable });
//Thread.Sleep(3000);
continue;
}
var ch = c.SkipUntilOrEmpty(" <div class=\"yt-user-info\">").SkipUntilOrEmpty("<a href=\"/channel/");
var ch_id = ch.TakeUntilOrEmpty("\"");
var ch_name = ch.SkipUntilOrEmpty(">").TakeUntilOrEmpty("<");
// https://www.youtube.com/channel/UCP-Q2vpvpQmdShz-ASBj2fA/videos
// ! originally there were users, now there are thos gplus accounts?
//var usertoken = c.SkipUntilOrEmpty("<link itemprop=\"url\" href=\"http://www.youtube.com/user/");
//var userid = usertoken.TakeUntilOrEmpty("\"");
////var ch_name = ch.SkipUntilOrEmpty(">").TakeUntilOrEmpty("<");
//var userurl = "https://youtube.com/user/" + userid;
Console.WriteLine(new { src, link, ch_name, ch_id });
//Console.WriteLine(new { page0, link });
// Our test youtube link
//const string link = "https://www.youtube.com/watch?v=BJ9v4ckXyrU";
//Debugger.Break();
示例8: DoVideo
// CALLED BY?
public static void DoVideo(string link)
{
//Debugger.Break();
try
{
// a running applicaion should know when it can reload itself
// when all running tasks are complete and no new tasks are to be taken.
var videoUrl = link;
var prefix2 = "//www.youtube.com/watch?v=";
var prefix = "//www.youtube.com/embed/";
//var prefix = "https://www.youtube.com/embed/";
var embed = link.SkipUntilOrNull(prefix) ?? link.SkipUntilOrNull(prefix2);
var id = embed.TakeUntilIfAny("\"").TakeUntilIfAny("?");
bool isYoutubeUrl = DownloadUrlResolver.TryNormalizeYoutubeUrl(videoUrl, out videoUrl);
//Console.WriteLine(new { sw.ElapsedMilliseconds, px, videoUrl });
// wont help
//var y = DownloadUrlResolver.GetDownloadUrls(link);
//var j = DownloadUrlResolver.LoadJson(videoUrl);
var c = new WebClient().DownloadString(videoUrl);
// "Kryon - Timing o..." The YouTube account associated with this video has been terminated due to multiple third-party notifications of copyright infringement.
// <link itemprop="url" href="http://www.youtube.com/user/melania1172">
// { videoUrl = http://youtube.com/watch?v=li0E4_7ap3g, ch_name = , userurl = https://youtube.com/user/ }
//{ url = http://youtube.com/watch?v=li0E4_7ap3g }
//{ err = YoutubeExtractor.YoutubeParseException: Could not parse the Youtube page for URL http://youtube.com/watch?v=li0E4_7ap3g
// <h1 id="unavailable-message" class="message">
// 'IS_UNAVAILABLE_PAGE': false,
var unavailable =
!c.Contains("'IS_UNAVAILABLE_PAGE': false") ?
c.SkipUntilOrEmpty("<h1 id=\"unavailable-message\" class=\"message\">").TakeUntilOrEmpty("<").Trim() : "";
if (unavailable != "")
{
Console.WriteLine(new { videoUrl, unavailable });
Thread.Sleep(3000);
return;
}
var ch = c.SkipUntilOrEmpty(" <div class=\"yt-user-info\">").SkipUntilOrEmpty("<a href=\"/channel/");
var ch_id = ch.TakeUntilOrEmpty("\"");
var ch_name = ch.SkipUntilOrEmpty(">").TakeUntilOrEmpty("<");
// https://www.youtube.com/channel/UCP-Q2vpvpQmdShz-ASBj2fA/videos
// ! originally there were users, now there are thos gplus accounts?
//var usertoken = c.SkipUntilOrEmpty("<link itemprop=\"url\" href=\"http://www.youtube.com/user/");
//var userid = usertoken.TakeUntilOrEmpty("\"");
////var ch_name = ch.SkipUntilOrEmpty(">").TakeUntilOrEmpty("<");
//var userurl = "https://youtube.com/user/" + userid;
Console.WriteLine(new { link, ch_name, ch_id });
//Console.WriteLine(new { page0, link });
// Our test youtube link
//const string link = "https://www.youtube.com/watch?v=BJ9v4ckXyrU";
//Debugger.Break();
// rewrite broke JObject Parse.
// Additional information: Bad JSON escape sequence: \5.Path 'args.afv_ad_tag_restricted_to_instream', line 1, position 3029.
// <script>var ytplayer = ytplayer || {};ytplayer.config =
var ytconfig = c.SkipUntilOrEmpty("<script>var ytplayer = ytplayer || {};ytplayer.config =").TakeUntilOrEmpty(";ytplayer.load =");
dynamic ytconfigJSON = Newtonsoft.Json.JsonConvert.DeserializeObject(ytconfig);
var ytconfigJSON_args = ytconfigJSON.args;
string ytconfigJSON_args_adaptive_fmts = ytconfigJSON.args.adaptive_fmts;
string adaptive_fmts = Uri.UnescapeDataString(ytconfigJSON_args_adaptive_fmts);
// projection_type=3
// + ((dynamic)((Newtonsoft.Json.Linq.JObject)(ytconfigJSON))).args
//var get_video_info = new WebClient().DownloadString("https://www.youtube.com/get_video_info?html5=1&video_id=" + id);
//.........这里部分代码省略.........
示例9: SecurityPartialTrustTest
public void SecurityPartialTrustTest()
{
// Repro: Astoria not working in partial trust with the EF
string savedPath = LocalWebServerHelper.FileTargetPath;
LocalWebServerHelper.Cleanup();
try
{
string[] trustLevels = new string[] { null, "High", "Medium" };
CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
new Dimension("trustLevel", trustLevels));
LocalWebServerHelper.FileTargetPath = Path.Combine(Path.GetTempPath(), "SecurityPartialTrustTest");
IOUtil.EnsureEmptyDirectoryExists(LocalWebServerHelper.FileTargetPath);
LocalWebServerHelper.StartWebServer();
TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
{
string trustLevel = (string)values["trustLevel"];
if (trustLevel == "Medium")
{
Trace.WriteLine(
"'Medium' trust level cannot be tested reliably in unit tests, " +
"because it may run into problems depending on the local file system " +
"permissions and/or the local web server (as far as can be told). " +
"You can still use the generated files to prop them to IIS, set up an application " +
"and test there.");
return;
}
// Setup partial trust service.
SetupPartialTrustService(trustLevel);
string address, text = null;
Exception exception;
address = "http://localhost:" + LocalWebServerHelper.LocalPortNumber + "/service.svc/ASet?$expand=NavB";
Trace.WriteLine("Requesting " + address);
exception = TestUtil.RunCatching(delegate() { text = new WebClient().DownloadString(address); });
WriteExceptionOrText(exception, text);
// Note: the second argument should be 'false' even for medium trust.
TestUtil.AssertExceptionExpected(exception, false);
// Invoke something that would normally fail.
address = "http://localhost:" + LocalWebServerHelper.LocalPortNumber + "/service.svc/Q";
text = null;
Trace.WriteLine("Requesting " + address);
exception = TestUtil.RunCatching(delegate() { text = new WebClient().DownloadString(address); });
WriteExceptionOrText(exception, text);
TestUtil.AssertExceptionExpected(exception,
trustLevel == "Medium" && !text.Contains("error") // The error may come in the body
);
});
}
finally
{
LocalWebServerHelper.DisposeProcess();
LocalWebServerHelper.Cleanup();
LocalWebServerHelper.FileTargetPath = savedPath;
}
}
示例10: CanAlterXsd
//[TestMethod]
public void CanAlterXsd()
{
host.AddMetadataMessageInspector(new EasyMetadataInterceptor()
{
Xsd = doc =>
{
var someType = doc.Descendants().Where((n) => n.Name.LocalName == "complexType").FirstOrDefault();
if (someType != null)
{
someType.AddFirst(EasyMetadataInterceptor.CreateDocumentationAnnotation(marker, "en"));
}
return doc;
},
});
host.Open();
var xsd = new WebClient().DownloadString(uri + "?xsd=xsd0");
Assert.IsTrue(xsd.Contains(marker));
}
示例11: InlineXsd
public void InlineXsd()
{
host.InlineXsdsInWsdl();
host.Open();
var wsdl = new WebClient().DownloadString(uri + "?WSDL");
Assert.IsTrue(wsdl.Contains(":schema"));
// there are a number of things we want to check here such as whether the dummy import namespace was deleted
// this Assert serves as a proxy: check that the default DC serialization schema got imported
Assert.IsTrue(wsdl.Contains("http://schemas.microsoft.com/2003/10/Serialization/"));
}
示例12: Post
public Post(string title, string url, string permalink, string user, string subreddit, string score, string nComments, string created, string thumbnail)
{
this.title = title;
this.url = url;
this.permalink = "http://www.reddit.com" + permalink;
this.user = user;
this.subreddit = "/r/" + subreddit;
this.score = int.Parse(score);
this.nComments = int.Parse(nComments);
this.created = Misc.ConvertFromUnixTime(created);
if (url.Contains("imgur") && !url.Contains("imgur.com/a/"))
{
if (url[url.Length - 4] != '.')
{
//find image extension
if (url.Contains("/gallery/"))
url = url.Replace("/gallery/", "/");
url = "http://api.imgur.com/oembed.json?url=" + url;
string jsonFile = new WebClient().DownloadString(url);
if (jsonFile.Contains("\"url\":\""))
{
int lb = jsonFile.IndexOf("\"url\":\"") + 7;
int ub = jsonFile.IndexOf('"', lb);
url = jsonFile.Substring(lb, ub - lb);
url = Regex.Unescape(url);
}
else
{
//no extension data present in xml file
url = this.url; //reset url
if (thumbnail != "")
image = "<image=" + thumbnail + ">"; //use thumbnail
else
image = "";
return;
}
}
if (!url.Contains("i."))
url = url.Replace("imgur.com", "i.imgur.com");
url = url.Insert(url.Length - 4, "l"); //download large version
image = "<image=" + url + ">";
}
else
image = "<image=" + thumbnail + ">";
}
示例13: GetShippingOption
private List<ShippingOption> GetShippingOption()
{
string request = _isDomenic
? UrlDomenic + GetXmlDomenicPackage()
: UrlInternational + GetXmlInternationalPackage();
string xml = new WebClient().DownloadString(request);
if (xml.Contains("<Error>"))
{
int idx1 = xml.IndexOf("<Description>") + 13;
int idx2 = xml.IndexOf("</Description>");
string errorText = xml.Substring(idx1, idx2 - idx1);
Debug.LogError(new Exception("USPS Error returned: " + errorText), false);
}
return ParseResponseMessage(xml);
}