Creating HTTPS login on iOS? - iphone

How do I build an https login on iOS? (Like this one: https://info.tam.ch/kks)
I only know how to solve a .htaccess.
Thank you.

I use ASIHTTPRequest in my iPhone project to communicate with the web application. For http authentication, they have a convenient ASIAuthenticationDialog class that takes care of that. Basic usage is as follows:
// Specifying a username and password to use in the URL
NSURL *url = [NSURL URLWithString:#"http://username:password#allseeing-i.com/top_secret/"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
// Setting a username and password to use on the request
NSURL *url = [NSURL URLWithString:#"http://allseeing-i.com/top_secret/"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setUsername:#"username"];
[request setPassword:#"password"];
You can visit here for detailed information or check out the sample source code here on github.

Related

ios managing authentication tokens from NSURLRequest / HTTP request

When I make a POST request to sign in from within the iPhone app I am developing, the request returns an authentication token that I can successfully store in an NSString to be used throughout the rest of the app.
However, for any request after the sign in, I must pass it this authentication token so the request knows that a user is logged in. What is the complete way to do this for an NSURLRequest / what parameters/values must i specify for the NSURLRequest? Thank you in advance.
These NSURLRequest methods might help you
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"yoururl.com"]];
[request setHTTPMethod: #"POST" ];
[request setValue:#"yourtoken" forHTTPHeaderField:#"header field"];
[request setHTTPBody: dataifneeded ];

get access to a file of another PC through NSURL

I can access to my local file through NSURL by using:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"file://localhost/Users/user/Desktop/lucky_numbers.json"]];
But I need to get access of a file of another PC.
I tried:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"file://foyzulkarim:000000#192.168.1.48/localhost/Users/foyzulkarim/Desktop/lucky_numbers.json"]];
and
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"file://192.168.1.48/localhost/Users/foyzulkarim/Desktop/lucky_numbers.json"]];
and
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"file://Foyzul-Karims-MacBook.local/localhost/Users/foyzulkarim/Desktop/lucky_numbers.json"]];
But Error shows NSURLError domain code -1100
Please help me if anyone knows how to do this.
I doesn't work that way. The file: URI scheme only supports local file access, not remote. For remote access you need a real network protocol like HTTP or FTP and thus a server on the remote site.
You can access to my local file through NSURL by using: NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"file://192.168.1.48/localhost/Volumes/foyzulkarim/Desktop/lucky_numbers.json"]];
but, to do this you have to first connect with that PC manually.

How to use post manner to transmit username and password in order to log in a website on iphone or ipad platform?

How to use post manner to transmit username and password in order to log in a website on iphone or ipad platform?
Some one has suggest me that use ASIHTTPRequest,but I don't know how to use it.
Can somebody help me ?Thank you ........
ASIHTTPRequest has one of the best how to use pages of any library I have ever encountered. It is located here: http://allseeing-i.com/ASIHTTPRequest/How-to-use
If you need to post to a web form you could do something like this:
#define kURLString #"https://yourwebsite.com"
NSURL *url = [NSURL urlWithString:kURLString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:#"myname" forKey:#"username"];
[request setPostValue:#"l33td00d" forKey:#"password"];
[request setDelegate:self];
[request startSynchronous];
Although in real life you may wish to run the request asynchronous. The details on how to do that are on the page I linked. It is defiantly worth reading.

graph.facebook.com and FacebookConnect on iPhone: How can I remove a "like"

I'm developing an iPhone application using the Facebook Connect API. I arrived to set the "Like" on a post using the following code:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/likes", discussion.postId]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:[self.facebook accessToken] forKey:#"access_token"];
[request setDelegate:self];
[request startAsynchronous];
It generates the following call:
HTTP POST https://graph.facebook.com/147512198609691_148877991806445/likes
But I'm not able to do the inverse operation "Unlike" (removing the like
from the post).
I tried the following:
HTTP POST https://graph.facebook.com/147512198609691_148877991806445/likes?access_token=....&method=delete
and also:
HTTP DELETE https://graph.facebook.com/147512198609691_148877991806445/likes?access_token=....
But those are not working, probably I'm using a wrong command.
[request setPostValue:#"DELETE" forKey:#"method"];

How can I send request and get a file response in iPhone?

My problem is the following...
I read about sending http requests and receiving their responses on iPhone SDK 3.2 using NSURLRequest and NSHTTPURLResponse (All my requests are "get" and there's no "post") but I don't know how to do that exactly cause some of my responses are just strings (plain text) and some others are binary files (gzip and mp3)
Thank you in advance for the help
To perform a Http request, I use ASIHttpRequest:
NSURL *url = [NSURL URLWithString:my_url];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:#"GET"];
[request startSynchronous];
That works perfectly. Still need to figure out if it's fine with mp3 / zip files.
Luc