I have the following code in objective c that is supposed to make a GET http request to my website which in turn will submit something into my MySQL database…
NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.website.com/VideoPush/plist/urlTransfer.php"]];
[request setHTTPMethod:@"GET"];
NSString *post =[[NSString alloc] initWithFormat:@"videoID=%@",videoURL];
[request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding]];
Note: I’m a total beginner to http requests with Objective c so I realize I could be missing something obvious…
Now if I run the following url in my browser…
http://www.website.com/VideoPush/plist/urlTransfer.php?videoID=hhklskdjsad
Then something gets entered into the database, but not when I’m using objective c. Also what is the difference between GET and POST when you make requests like this (since the user doesn’t see the url anyways)?
ALSO: Am I allowed to pass a url (still a nsstring with /’s though) as the videoURL variable above
You’ve tried to set the body of a GET request, which makes no sense. What you probably want is:
You should probably go and have a read up about what a GET and a POST is and why I said it makes no sense to have a body in a GET request.
No, you will need to URL encode anything in the query string. You can use
CFURLCreateStringByAddingPercentEscapesto do this for you.