get access to a file of another PC through NSURL - iphone

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.

Related

Get cookie from NSURLRequest to WebView

The goal of my program is to do the following:
Execute a url on my website, which 'logs' the user in using NSURLRequest. Basically my thought is to execute the request, get the cookie from the response and add the cookie to the WebView.
All I know how to do is execute the first part of this process, and the code is below for that:
NSString *fullURL = #"http://mysite.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
content is the name of my webview
[content loadRequest:theRequest];
Next up is parsing the response. Basically check for error (the page only outputs the word 'true' or 'false' for error. I'm guessing I can check for the existence of those words and act appropriately. And of course, getting a cookie from the response and sending it to 'content'. Would appreciate help, thanks!
Normally URL loading system automatically handles sending and storing all URL related cookies with your NSURLRequest. However if you want to add an extra cookie, you must use NSMutableURLRequest.
Cookies are part of request response headers, which you can modify like this:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request addValue:cookie forHTTPHeaderField:"Cookie"];

Using gzcompress in PHP; need to be able to uncompress on iPhone

I'm sure this isn't too difficult (and I'm surprised I can't figure it out), but here goes:
So. I'm using gzcompress() to compress JSON data in PHP so I can send it into an iPhone app.
Having some troubles figuring out how to uncompress this data on the iPhone (iOS).
Any thoughts? I'm grabbing the data via a NSMutableURLRequest.
Thanks!
Code making the request:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:theURL]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
Code processing the response:
NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] autorelease];
And on the PHP side:
echo(gzcompress(json_encode($lines)));
Thanks!!!
This article suggests that NSMutableURLRequest supports gzip decompression out-of-the-box, but you need to add an Accept-Encoding: gzip header to the request.
Extending your example:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:theURL]];
[request setValue:#"gzip" forHTTPHeaderField:#"Accept-Encoding"];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
I'd also recommend testing the PHP script with cURL to make sure it's sending valid gzipped data.

Creating HTTPS login on iOS?

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.

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