iPhone send user location to PHP script - iphone

Hi I am currently designing my second iphone app, and having a small issue.
I have the location code working correctly but I have no idea how to send the label with the location info to my server.
I was wondering and hoping someone might be able to help.
Thanks
Russell

That would depend entirely on what your PHP script expects to receive. Your most obvious choices would be to put the coordinates in the query string or in a POST request.

Use ASIHTTPRequest for http requests. http://allseeing-i.com/ASIHTTPRequest/
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:#"Josh" forKey:#"first_name"];
[request setPostValue:#"Highland" forKey:#"last_name"];
[request start];

Related

Get Multiple download progress update of each download using NSOperationQueue and ASIHTTPRequest

iam using to download multiple file using by pass ASIHTTPRequest to operation queue...
NSInvocationOperation *operation =[[NSInvocationOperation alloc]initWithTarget:self selector:#selector(DownloadFile:) object:url];
.
.
.
-(void)DownloadFile:(NSURL)url{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDownloadProgressDelegate:self];
[request setDidFailSelector:#selector(requestWentWrong:)];
[request setDidFinishSelector:#selector(requestFinished:)];
[request setDelegate:self];
[request startSynchronous];
}
- (void)setProgress:(float)progress{
NSLog(#"Current progress %f :",progress);
}
The progress is working fine but i can't know from which URL or from which operation..
I want to know how to get each download progress of each url individually...
and how i cancel each one not cancel all operations.
Thanks
First an answer to your question: how about you create one "delegate" object for each download? Then it's obvious how download progresses for each download and cancel is easy, too. The code will be more complicated, though.
Therefore I have another suggestion: the author of ASIHTTPRequest library has stopped developing the library, so you might switch to something else. He's suggestion for example AFNetworking, but many people recommend nowadays MKNetworkKit. It seems to have pretty good queue handling.
Note the signature of the delegate messages: Each one takes an argument. That argument is the request sending you the message: The request, when it sends you a delegate message, includes itself among the arguments so that you know which request has gotten that far.

Tracking download progress of a response to a ASIFormDataRequest

I am sending a request with POST data to a web server. The web server returns with JSON response in case of an error or the file data itself if there are no errors.
I would like to track the progress of the file data response. My code is based on the the sample code from ASIHttpRequest Tutorial
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:someValue forKey:#"someKey"];
[request setPostValue:someOtherValue forKey:#"someOtherKey"];
[request setShowAccurateProgress:YES];
[request setDownloadProgressDelegate:aProgressView];
request.delegate = self;
[request startSynchronous];
Nothing happens until the complete response is there, in which case the progress bar fills up completely.
I experimented with both synchronous and asynchronous requests.
I guess the download progress delegate does not work, because I am not downloading a file per se, but just receiving the HTTP response to the request, right? What would be the correct approach to monitor the progress in this case?
Thanks in advance...
Are you running this code in the main thread?
If so the reason the progress doesn't update is that using a synchronous request will be blocking the main thread, preventing UI updates from happening.
The best fix for that is to use an asynchronous request - you mentioned you've tried that, what happened?
Tip:
Print http response and check if you have Content-Length. If not, or it's 0 that's the problem.
NSLog(#"Response headers %#",[request responseHeaders]);

iOS: How to make a secure HTTPS connection to pass credentials?

I am creating my first iPad app. I have a web application that I would like to authenticate against and pull data from in a RESTful way.
If you open up the URL in the browser (https://myapp.com/auth/login), you will get a form to enter your username and password. I was thinking I could set the login credentials in the post data of the request and submit the data.
The site uses HTTPS for login so that credentials aren't passed in plain text over the internet.
How can I make a secure HTTPS connection to pass credentials? Will this remember that I am logged in for future requests? What is the best way to do this?
Further update, October 2013
Although at the time I wrote this answer, ASIHTTPRequest was maintained a widely supported, this is no longer the case. It is not recommended for new projects - instead use NSURLConnection directly, or use AFNetworking.
With AFNetworking, there is a [httpClient setAuthorizationHeaderWithUsername:username password:password]; method for http authentication, and create a POST style form is equally easy - see AFNetworking Post Request for that.
Original answer:
A lot of people use the ASIHTTPRequest class to deal with http & https on the iPhone/iPad, as it has a lot of useful features that are difficult or time consuming to achieve with the built in classes:
http://allseeing-i.com/ASIHTTPRequest/
Starting at the simplest level you'd start with something like:
NSURL *url = [NSURL URLWithString:#"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
NSLog(#"response = %#", response);
}
If you're using HTTP authentication, ASIHTTPRequest will automatically prompt the user for the username and password.
IF you're using some other form of authentication you probably need to request the username and password from the user yourself, and submit them as a POST value or a custom http header, and then the response may either include a token in a JSON or XML response, or it could set a cookie.
If you add more details as to how the authentication scheme works I can be a bit more specific.
Update
Based on the update, to emulate a POST form you'd just need to add lines like:
[request addPostValue:usernameString forKey:#"username"];
[request addPostValue:passwordString forKey:#"password"];
You will also need to change the way you create the request, instead of:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
do:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
(I also forget to mention it above, there's code I put earlier is using a synchronous request, so you'd want to replace it with an asynchronous one to avoid blocking the UI once you'd proved it was working.)
There's a JSON framework for the iphone here:
http://code.google.com/p/json-framework/
which works well for me and is simple to use with ASIHTTPRequest.

How to generate an NSURLRequest to download a file from a WebDAV server like MobileME

Should I mention
[request setHTTPMethod:#"GET"] ?
and what should I enter in the
[request setHTTPBody: ?] ?
OR should I just leave it empty?
Please help.
Thanks in advance.
Well in case any body would like to know , my assumptions work fine.
just have to set the [request setHTTPMethod:#"GET"]; and then making a NSURLConnection with such request Downloads the specified content at that URL.

ASIHTTPRequest on www.blau.de?

I need to login here. I've tried the ASIHTTPRequest and ASIFormDataRequest.
None of them works as expected. I only got the data from the loginpage in the response string, not the data from the secure area.
What am I doing wrong here?
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:#"https://www.blau.de/"]];
[request setPostValue:#"USERNAME" forKey:#"quickLoginNumber"];
[request setPostValue:#"PASSWORD" forKey:#"quickLoginPassword"];
[request startAsynchronous];
There are a couple of good tools you can use to try to debug this. In all likelihood there is a 302 redirect after logging in. You can watch for that (among other conditions) using tools such as:
HTTPScoop (worth the $15 bux): http://www.tuffcode.com/
Live Headers (a free FireFox plugin): https://addons.mozilla.org/en-US/firefox/addon/3829/
Keep in mind that what you're trying to do is not simple. I've gotten it to work with some sites, but not others and the reasons for one or the other can be quite elusive.