Post comment to WordPress Blog from iPhone programmatically - iphone

I installed the WordPress blog on my localhost server and also made an iPhone app to browse the blog via rss. I tried to post a comment programmatically using this code.
#define post_url #"http://localhost/web-wp/wp-comments-post.php"
#define post_content #"comment_post_ID=%#&comment_parent=%#&author=%#&email=%#&comment=%#"
NSString *post_str = [NSString stringWithFormat:post_content, #"1", #"0", #"Viet", #"vietnt88#gmail.com", #"test. comment written on mobile"];
NSData *data = [post_str dataUsingEncoding:NSUTF8StringEncoding];
NSURL * url = [NSURL URLWithString:post_url];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url];
[req setHTTPMethod:#"POST"];
[req setHTTPBody:data];
NSURLResponse *response;
NSError *err;
[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
I need this code to work when the user is not logged in. How do I achieve that?
How can I post comment from iPhone?

First of all, if you use "localhost" from your code running on your iPhone, then "localhost" will refer to the iPhone not to your web server. Put there the IP of your server, if you have a public IP than that one otherwise connect your iPhone via WiFi to the same LAN as your local server and use the IP of that server (I guess it'll be something like 192.168...).

Related

save sign up view controller text values on the server through php web service call using post method in iOS

i have sign up form in which i have the fields like first name,last name,gender,email,password,user image,age. i want to make save this user information on the server through php webservice call.how can i pass these parameters to service url? will i use the http request using post method to save the user info to server and when that user wants to log in iOS app , i may match the credencial for that user. in shore, i need a log in and sign up screen for my iOS app, please suggest me any tutorial
Thanks in advance to all of you
First you need nto create php script and then transfer data through NSURL.
NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:#"http://192.168.0.6/savedevicedata.php?Udid=%#&Flag=%d&DateTime=%#",uniqueIdentifier,Flag,FinalDate]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSLog(#"%#",request);
[request setHTTPMethod:#"POST"];
//[request setHTTPBody:[NSString stringWithFormat:#"%#",rawStr]];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(#"responseData: %#", responseData);
Try this Code just replaces the your field.

Getting Metadata from shoutcast iOS programming

Hello I am trying to parse Shoutcast radio's metadata in iOS.
After trying many submitted solutions, I end up with a piece of code that is still giving me error
Response String: ICY 404 Resource Not Found
icy-notice1:SHOUTcast Distributed Network Audio Server/Linux v1.9.8
icy-notice2:The resource requested was not found
the code im trying to parse metadata
NSURL *url = [NSURL URLWithString:#"http://relay.181.fm:8052/7.html"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15.0];
[request addValue:#"1" forHTTPHeaderField:#"icy-metadata"];
[request addValue:#"Winamp 5/3" forHTTPHeaderField:#"User-Agent"];
[request addValue:#"audio/mpeg" forHTTPHeaderField:#"Content-Type"];
[request setHTTPMethod:#"GET"];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString* responseString = [[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding];
NSLog(#"Response String: %#", responseString);
any ideas about problem, thanks for helping
Not all SHOUTcast servers allow access to 7.html. There are two other ways to get that data.
The XML data for SHOUTcast is generally available, but requires the server's password. You can request it using /admin.cgi?mode=viewxml&page=4.
You can also read the metadata right out of the stream. This is more cumbersome, but entirely possible, and not too difficult. See this answer for details: https://stackoverflow.com/a/4914538/362536
I found a solution for those who can't/doesn't want to read metadata from stream.
Its the easiest solution I have seen.
http://www.fvalente.org/blog/2012/03/15/shoutcast-metadata-the-easy-way/
Brad says in the post above
Not all SHOUTcast servers allow access to 7.html.
so it is better to check if the server you want to get metadata has /7.html page
the current song is also displayed on the page /played.html but it works in a web browser along with /7.html. But when i tried in fiddler2 on a windows machine i got the ICY 404 resource not found error

Sending a request from iphone to webserver

This may be a simple question but i'm a newer to web service programming.
What i need is to send a recipe to a database and the administrator has to approved it.
I'm handling with the server side program for the first time.sorry for this.
So can anyone kindly help me how to send large datas from iphone to webservice.
Thanks in advance.
For example : Suppose You want to pass user name and password to server. Then you can pass it with the web services. By :
NSString *urlStr = [NSString stringWithFormat:#"%#?method=login&emailId=%#&Password=%#&iphonekey=%#",aWebserviceURL,username,password,aIphoneKey];
NSLog(#"Login - %#",urlStr);
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
NSMutableData *responseData;
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding] autorelease];
NSLog(#"%#",responseString);
Here username,password,aIphoneKey are the Parameters of web service.
I'm assuming you're meaning from an iPhone app to webserver?
If that's the case there's a decent article on making web requests in Objective C here
And a good intro here also

Sending post request does not send post body to server

I have the following code used to post data to a remote server:
NSString *urlStr = [[NSString alloc] initWithFormat: #"http://www.myserver.com/%#",program ];
NSString *postBody =[[NSString alloc] initWithFormat:#"uid=%#",parms];
NSMutableURLRequest *request;
NSData *postData = [postBody dataUsingEncoding:NSISOLatin1StringEncoding];
NSError *error;
NSURLResponse *response;
NSData *dataReply;
request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:urlStr]];
[request setHTTPMethod: #"POST"];
[request setHTTPBody:postData];
dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
serverResponse = (NSString *)[[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
[postBody release];
[urlStr release];
program is the php program to run on the server. parms is the string to be posted in the format:
\ntoken=12345
Here's the problem: This works fine from the simulator. It works fine on my 3gs development phone. It works fine on a beta tester's 3gs phone that I emailed the app to. It does NOT work fine on another beta tester's iPhone 4 (emailed to him the exact same provision file and ipa file). The POST call is made from the iPhone 4 to the server but no post body is passed. I log each of the calls to the server on the server. The post body is there for the 3gs phones, not for the 4 phone. There are no errors generated in the Apache logs.
Is there some difference between the two phone models that I need to account for? I have tried both http and https access with the same behavior. I don't currently have access to an iPhone 4 so any insight would be a great help.
The answer is not model related. It has to do with the name of the phone which is passed as a parameter to the server. The name contains an apostrophe as in Mike's iPhone.

API image file upload iPhone to Ruby on Rails

I am a backend Rails developer of an API that services several iPhone clients. I'm not an iPhone dev.
I have a need to accept binary data (several image files in this case) from the client via a POST request to the API.
To get the file content (file metadata other than image type is not relevant here), what tools might be used by the iPhone developer? I've found ObjectiveResource (used by iPhone on Rails) and ASIHTTPRequest. In the pages I found for those, there's no indication of what form the uploaded file will have when the controller action is executed. Will it be a Ruby File object or Tempfile object? I don't control the iPhone code development, there are some cross-cultural communication difficulties there, and they haven't used those suggestions so far. If I can submit better information to them, I might be getting better data back.
The backend app is currently running Rails 2.3.10, and will soon (in the next few weeks) likely be converted into Rails 3.
Thanks,
Craig
ObjectiveResource does not natively support file uploads. Try instead using ASIHTTPRequest with this snippet:
NSURL *url = [NSURL URLWithString:#"http://localhost:3000/file"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:#"Sample" forKey:#"name"];
[request setFile:... forKey:#"file"];
[request startSynchronous];
For more details, see the example page here (sending data).
The post will be encoded as a standard multipart form post (just like if it came from an HTML form). If you are using paperclip to store your uploads, the magic will just happen!
Use JSON over HTTP
NSMutableURLRequest *request =
[[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:urlStr]];
[request setHTTPMethod: #"POST"];
[request setValue:#"application/json; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
NSString* requestDataLengthString = [[NSString alloc] initWithFormat:#"%d", [jsonMessageStr length]];
[request setValue:requestDataLengthString forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
[request setHTTPBody:jsonData];
NSURLConnection *theConnection =
[[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];