【问题标题】:Simulating a website in an application在应用程序中模拟网站
【发布时间】:2015-11-29 21:06:54
【问题描述】:

我首先尝试在 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

我错过了什么吗?还是我的方向完全不同?

【问题讨论】:

  • 如果您用浏览器右键单击“报告”按钮,您会看到标记中它的正下方是一个锚标记,其 URL 指向“9gag.com/read/delete?id=aKBQ00O”。似乎向该 URL 发出 HTTP 获取请求足以完成您的任务。
  • @mason 这是您想删除帖子的时候。 (因为不是你的帖子所以被隐藏了)
  • 我没有检查它请求的实际 URL。删除了我的答案
  • 查看源码,表单没有“method”属性。它将使用查询字符串发送数据。看到@mason的评论后,我删除了我的答案。
  • 正在运行 javascript,最终方法是 POST,最终的 Url /report-post 和要发送的数据看起来像 entryId=aKBQ00O&type=4

标签: c# html webclient


【解决方案1】:

通过开发者工具网络标签检查

我可以看到它实际上发布到

http://9gag.com/report-post

数据如下:(type = 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);
}

【讨论】:

    猜你喜欢
    • 2014-12-15
    • 2019-07-22
    • 2021-11-24
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    • 2016-07-11
    相关资源
    最近更新 更多