HTTP POST请求,HTML表单输入(登录:用户/密码)浏览器模拟 [英] HTTP POST Request, HTML Form input (login: user/password) browser simulation

查看:1255
本文介绍了HTTP POST请求,HTML表单输入(登录:用户/密码)浏览器模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的应用程序中登录一个网站(http://www.meo.pt/ver/Pages/login.aspx)以便我可以访问程序列表等,我在用户名文本框和密码文本框输入的html页面源代码。

I'm trying to login to a website (http://www.meo.pt/ver/Pages/login.aspx) from within my application so that I can access the program listing, etc, I searched in the page source code for the html for of the username textbox and password textbox input.

<input name="ctl00$SPWebPartManager1$g_cb264700_1517_426f_926d_3ca40934a6fd$ctl00$EditModePanel1$txtUserName"
       type="text" 
       id="ctl00_SPWebPartManager1_g_cb264700_1517_426f_926d_3ca40934a6fd_ctl00_EditModePanel1_txtUserName"
       class="forms_login"  />

我使用 name 中的值并设置该密钥的内容与用户名和密码相同。然后向 http://www.meo.pt/ver/Pages/login.aspx 发出POST请求,我从中获得了包含同一页面的HTML源代码的响应,所以登录不成功。我不认为服务器甚至认为它是登录尝试。

I used the value in name and set the content of that key with the username and the same form the password. Then made a POST request to http://www.meo.pt/ver/Pages/login.aspx from which I got a response containing the HTML source of the same page, so login wasn't successful. I don't think the server even considered it a login try.

我的问题是我应该如何设置POST请求值以使其工作?
我正在使用ASIHTTPRequest for iPhone。

My question is how should I set the POST request values to make this work? I'm using ASIHTTPRequest for iPhone.

推荐答案

我的猜测是它与cookie有关:页面发送一个cookie出现时需要cookie以及用户名和密码。很有可能每个POST和GET都会返回一个cookie以及页面内容,这是一个你需要发回的cookie。

My guess is that it's cookie-related: the page sends a cookie when it appears and requires that cookie along with the username and password. Odds are good that every POST and GET returns a cookie along with the page content, a cookie you'll need to send back.

如果你使用ASIHTTPRequest来执行请求并使用相同的对象实例来进行后续请求,每次都会负责发送修改后的cookie。我喜欢这个图书馆并推荐它。

If you use ASIHTTPRequest to perform the requests and use the same instance of the object to make subsequent requests, it will take care of sending those revised cookies each time. I love this library and recommend it.

http:/ /allseeing-i.com/ASIHTTPRequest/

如果您使用的是NSURLConnection并且更喜欢自己管理cookie,那么NSHTTPCookie对象将有所帮助。

If instead you're using an NSURLConnection and prefer to manage the cookies yourself, the NSHTTPCookie object will help.

这篇关于HTTP POST请求,HTML表单输入(登录:用户/密码)浏览器模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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