[英]Simulating a website in an application
我尝试通过以下操作在9GAG上模拟报告按钮:
string url = "http://9gag.com/gag/aKBQ00O";
string parameters = "radio-report=1";
using( WebClient wc = new WebClient( ) ) {
wc.Headers[ HttpRequestHeader.ContentType ] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString( url, parameters );
Console.WriteLine( HtmlResult );
}
并且发生WebException
并显示一条消息,提示服务器发送了404 NOT FOUND
错误。 对于那些不想去9GAG看到我正在模拟的表格的人,这里:
<section id="modal-report" class="badge-overlay-report modal report">
<header>
<h3>Report Post</h3>
<p>What do you report this post for?</p>
<a class="btn-close badge-overlay-close" href="#">✖</a>
</header>
<form id="form-modal-report" class="popup-report" action="" onsubmit="return true;">
<div class="field checkbox">
<label><input name="radio-report" type="radio" value="1"> Contains a trademark or copyright violation</label>
</div>
<div class="field checkbox">
<label><input name="radio-report" type="radio" value="2"> Spam, blatant advertising, or solicitation</label>
</div>
<div class="field checkbox">
<label><input name="radio-report" type="radio" value="3"> Contains offensive materials/nudity</label>
</div>
<div class="field checkbox">
<label><input name="radio-report" type="radio" value="4"> Repost of another post on 9GAG</label>
<input id="jsid-repost-link" type="text" class="text" placeholder="http://9gag.com/gag/post_ID">
</div>
<div class="btn-container">
<input type="submit" value="Submit" data-text-loading="Please wait ...">
</div>
</form>
</section>
它当然取自http://9gag.com/gag/aKBQ00O 。
我想念什么吗? 还是我处于完全不同的方向?
通过开发者工具检查网络标签
我可以看到它实际上发布到
http://9gag.com/report-post
数据如下:(第四个单选按钮的类型= 4)
entryId=aKBQ00O&type=4&link=
因此,您应该像这样更改代码:(但是应该动态定义类型和链接参数)
string url = "http://9gag.com/report-post";
string parameters = "entryId=aKBQ00O&type=4&link=";
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(url, parameters);
Console.WriteLine(HtmlResult);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.