使用AFNetworking登录Instapaper(Logging into Instapaper with AFNetworking)

系统教程 行业动态 更新时间:2024-06-14 17:04:03
使用AFNetworking登录Instapaper(Logging into Instapaper with AFNetworking)

如果我想在用户已将用户名和密码放在UITextField中并使用AFNetworking登录的应用程序中登录Instapaper( http://www.instapaper.com/user/login ),我该如何做到这一点?

这个方法有用吗? http://afnetworking.github.com/AFNetworking/Classes/AFHTTPClient.html#//api/name/postPath:parameters:success:failure :

基本上我想获取凭据,登录Instapaper然后与加载的网站进行交互。

如果是上面的方法,我是否使用NSDictionary作为参数,其中'用户名' - >''和'密码' - >''或其他什么? 并且是登录后呈现的页面的HTML响应(我正在寻找什么)?

我是网络新手,所以我有点困惑我如何使用AFNetworking来实现这一目标。

If I wanted to login to Instapaper (http://www.instapaper.com/user/login) within an app where the user has put the username and password within a UITextField and login using AFNetworking, how would I accomplish this?

Is it to do with this method? http://afnetworking.github.com/AFNetworking/Classes/AFHTTPClient.html#//api/name/postPath:parameters:success:failure:

Basically I want to take the credentials, log in to Instapaper and then interact with the website that loads.

If it is the above method, do I use an NSDictionary for parameters where it's 'username'->'', and 'password'->'' or something? And is the response the HTML of the page that presents after login (what I'm looking for)?

I'm new to networking, so I'm a little confused how I'd use AFNetworking to accomplish this.

最满意答案

使用AFHTTPRequestOperation变量AFHTTPClient ,如果您要发送用户名和密码作为参数,然后将它们添加到NSDictionary中,如下所示并将它们作为参数发送,否则您可以将它们作为formData发送,如果您想在体内发送它们。

NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setObject:username.text forKey:@"username"]; [parameters setObject:password.text forKey:@"password"]; AFHTTPClient *afHttpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://yourbaseURL"]]; NSMutableURLRequest *request = [afHttpClient multipartFormRequestWithMethod:@"POST" path:@"/pathifAny" parameters:parameters constructingBodyWithBlock:^(id <AFMultipartFormData>formData) { // here you can send as body if you not setting as parameters [formData appendPartWithFormData:[username.text dataUsingEncoding:NSUTF8StringEncoding] name:@"username"]; [formData appendPartWithFormData:[password.text dataUsingEncoding:NSUTF8StringEncoding] name:@"password"]; }]; AFHTTPRequestOperation *afHttpReqOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

这是关于GET / POST的简单教程

Use AFHTTPRequestOperation variant of AFHTTPClient, If you are sending username and password as parameters then add them into a NSDictionary as follows and send them as params, otherwise you can send them as formData if you want to send them in the body.

NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setObject:username.text forKey:@"username"]; [parameters setObject:password.text forKey:@"password"]; AFHTTPClient *afHttpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://yourbaseURL"]]; NSMutableURLRequest *request = [afHttpClient multipartFormRequestWithMethod:@"POST" path:@"/pathifAny" parameters:parameters constructingBodyWithBlock:^(id <AFMultipartFormData>formData) { // here you can send as body if you not setting as parameters [formData appendPartWithFormData:[username.text dataUsingEncoding:NSUTF8StringEncoding] name:@"username"]; [formData appendPartWithFormData:[password.text dataUsingEncoding:NSUTF8StringEncoding] name:@"password"]; }]; AFHTTPRequestOperation *afHttpReqOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

Here is simple tutorial about GET/POST

更多推荐

本文发布于:2023-04-24 21:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/93f411c941ca5285029f426bcdf0841b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AFNetworking   Instapaper   Logging

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!