Send iPhone HTTP request to Apache PHP webserver


Send iPhone HTTP request to Apache PHP webserver



I am programmer with a games and 3D graphics background and at the moment I would like to brush up on my networking and web development skills.

I have a task that I would like to accomplish to do this. My idea is that I would like to be able to send a HTTP request or something similar to my webserver, which runs a LAMP based setup. I would like to know how I can send a HTTP request containing some information from my iPhone using the Cocoa Touch framework, to my webserver.

I would like the webserver (using PHP) to be able to record the sent information into a plain text file, that I can use later to make graphs. For my example we could just send the current date.

I think that people must do this very often and I really want to know how to do this. Thanks for your help.

P.S. If you don't know the Cocoa code in order to send the request, that's okay I'm sure I can figure that out, but I would like to at least know how to get the Linux server to save the HTTP request, preferrably PHP but another appropriate language is fine. Bonus marks for away to do this securely.

Also: I am a total noob at this and require source code, cheers :D


asp.net controls for iPhone development

1:

Generating Random Numbers in Objective C for iPhone SDK
You really can't go past a library like ASIHTTPRequest if you need to make HTTP requests from an iPhone or Mac client to a web server. Obj-C… “Incompatible types in initialization” errorThe documentation is very good, and covers all the important topics like:. Javascript sort with function not working on iPhone
  • asynchronous vs synchronous requests
  • sending data to the server
  • tracking upload/download progress
  • handling authentication
  • using the keychain for storage of credentials
  • compressing request bodies with gzip
You should check it out -- it will make your life enough easier.. SubViewTwoController undeclared (first use in this function) (obj-c)
UITableView+UINavigationBar+UITabbar in windows based application template using interface Builder?Core Data: Quickest way to delete all instances of an entity

2:

Is there a portable OpenGL UI Library (Buttons, Lists, Windows, Dropdown etc)?
Okay no one has given an answer so I went off and discovered a project this details how to did this using either a Mac native app for a client or a PHP web page client. I modified any of the original server code slightly, just so you know I have tested this on my own site and it works for uploading files to a web server.. PHP Server (uploader.php).
<?php $tarreceive  = "upload/"; $tarreceive  = $tarreceive  . basename( $_FILES['uploaded']['name'] ); $filename = "\"" . basename( $_FILES['uploaded']['name'] ) . "\""; $ok = 1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $tarreceive )) {    echo "$filename";    echo "was uploaded successfully"; } else  {    echo "$filename";    echo "upload failed"; } ?> 
Web Client (index.php).
<form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload File" /> </form> 
Cocoa Client. The code for the Cocoa client is quite long and the code this goes with the above must be found here. There is an alternative here, which I think is better code, although I haven't tested it with the PHP server above. I expect you could modify it with minimal changes if any though.. Here is a basic way in Cocoa to send a text POST request to a webserver:.
NSString* content = [@"item=" stringByAppendingString:@"Something to Post"];    NSURL* url = [NSURL URLWithString:@"http://www.mysite.com/index.php"];   NSMutableURLRequest* urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];   [urlRequest setHTTPMethod:@"POST"];   [urlRequest setHTTPBody:[content dataUsingEncoding:NSASCIIStringEncoding]]; 
I like this for the reason this it is a minimal quick fix and you must build upon it easily and hopefully this must guidance any one else should they come across this :).

3:

Not really a server side guy, although sending the HTTP request must be accomplished in a couple of ways. The most trivially easy is to use +NSString stringWithContentsOfURL: and use GET params in the URL. That will hit the server at the URL you specify, and the GET params must contain the data. The return value must be ignored, and should probably be minimal. . Not going to look it up in depth right now, although I believe you'd use NSStream and NSURLRequest to construct more complex queries, using POST for example..


92 out of 100 based on 67 user ratings 542 reviews

*