【问题标题】:Pass HTML Credentials into <input> using NSURL使用 NSURL 将 HTML 凭据传递到 <input>
【发布时间】:2014-03-19 14:10:09
【问题描述】:

Mistar website 上,我正在尝试使用 NSURLSession 从 iOS 应用程序发出请求,该应用程序在后台加载上面的网站,将用户名和密码的两个字符串传递给 &lt;input&gt;,然后让我访问登录页面。

这是相关的 HTML,它是一个有两个输入表单的表格,pin 是用户名,然后是密码:

<div class="widgetbdy" style="border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;">
        <table border="0" cellpadding="2" cellspacing="0" class="txtin3" style="width:100%; border-collapse: collapse">
            <tbody><tr style="height:10px;">
                <td colspan="2" style="height:10px;"></td>
            </tr>
            <tr style="padding-top:4px;">
                <td align="right" style="width:30%;">

                        <b><label for="ID" id="lblID">ID</label>:</b>

                </td>
                <td align="left">
                    <input class="txtin" id="Pin" name="Pin" onfocus="clearmessages()" style="width:175px;" type="text" value="">
                </td>
            </tr>
            <tr>
                <td align="right" style="width:30%;">
                    <b><label for="Password" id="lblPassword">Password</label>:</b>
                </td>
                <td align="left">
                    <input class="txtin" id="Password" name="Password" onfocus="clearmessages()" style="width:175px;" type="password" value="">
                </td>
            </tr>
            <tr>
                <td id="loginerrormsg" align="center" colspan="2">
                    <img id="imgwait" src="./Student Portal_files/ajax-loader.gif" width="20" height="20" alt="" style="display:none;">
                    <div id="msg1" style="display: none;" class="error"><label for="idandpasswordrequired" id="lblidandpasswordrequired">ID and Password Required</label></div>
                    <div id="msgdisplay" style="display: none;">
                    <div id="msgmessage" style="text-align:center; padding-bottom:10px;" class="error"></div>
                    </div>
                </td>
            </tr>
            <tr>
                <td align="right" colspan="2">
                    <input id="LoginButton" style="visibility: visible" type="button" value="Log In">
                </td>
            </tr>

            <tr style="height:10px;">
                <td colspan="2" style="height:10px;"></td>
            </tr>
        </tbody></table>
    </div>

【问题讨论】:

    标签: html ios http nsurl nsurlsession


    【解决方案1】:

    您可以通过创建屏幕外 UIWebView 和填充必填字段并执行表单提交的小 javascript 来做到这一点。

    或者另一种方式,如果网站没有那么难实现,您可以直接向身份验证 URL 发出 POST 请求,而无需 html 表单

    【讨论】:

    • 我如何POST 到授权网址?
    • 例如,使用一些代理,比如 Fidler 来记录浏览器的帖子并在 iOS 代码中做同样的事情
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    相关资源
    最近更新 更多