i m developing an ipad app for hospital management were information is filled in the user interface and on the click of a button the data is to be transfered to an external database(which later be viewed)...what are the steps required
You need to set up a webservice (like Saurabh said), for instance a PHP file using an mySQL connection would do fine.
To post the data (unsecured) to the service you can dome something like this:
NSString *post = #"key1=val1&key2=val2";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:#"http://www.someurl.com"]];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content- Type"];
[request setHTTPBody:postData];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
Read the NSURLConnection documentation
You need to create webservices on your server to add data in your database
see the answer of this question to know how to send data
Send data from an iPhone to a Web service
Related
Is it possible to check the data which I have sent in HTTP POST request, by logging the request in XCode.
Here is my code:
NSString *post = [NSString stringWithFormat:#"Firstname=%#&Lastname=%#&Email=%#",firstName,lastName,emailId];
NSLog(#"%#", post);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%d",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:#"http://www.abcde.com/xyz/login.aspx"]];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:postData];
**NSLog(#"%#", request );**
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
I am logging the request as shown above in Bold. But here I am able to see only my Url and not any post data.
If it is not possible to see data here where can I see the data sent in http request.
If you want just check what data are you sending then I suggest you to use this awesome tool http://www.charlesproxy.com. It's very simple and powerful.
Just run Charles and do your request via simulator.
good afternoon
I have been looking but I haven't found anything similar
I am starting with Xcode and objective C please you be patient with me
I want do this
I have a text field intended to be a search box
currently I send a POST request programmatically and the parameters are static
well, I want dynamic parameters
the content of the text field is dynamic parameters
how do I can do it?
I have also a button for sending the request
help please
this is code of the request
NSString *Post = [[NSString alloc] initWithFormat:#"query=deporte"];
NSURL *Url = [NSURL URLWithString:#"http://www.laleo.com/ebooks_android/ebooks_search_json.php"];
NSData *PostData = [Post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%d", [PostData length]];
NSMutableURLRequest *Request = [[NSMutableURLRequest alloc] init];
[Request setURL:Url];
[Request setHTTPMethod:#"POST"];
[Request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[Request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
[Request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[Request setHTTPBody:PostData];
NSData *returnData = [NSURLConnection sendSynchronousRequest:Request returningResponse:nil error:nil];
//NSString *myString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSError *error;
NSMutableDictionary *allCourses = [NSJSONSerialization
JSONObjectWithData:returnData
options:NSJSONReadingMutableContainers
error:&error];
The text field already is available through of #synthesize palabra;
The button is in the graphical interface
First of all, you should create an action handler for your button. Use Interface Builder for that. Also you'll need to connect the outlet for the textfield with your viewcontroller's class. Then, just take a text value from your textfield and send it into the request. If you need to know how you can receive a text from the textfield, just use this:
NSString *text = _textField.text;
I want to build up a login page and the values of this page i want to submit in server through a specific link. can any one send the code that how i will send the data into server?
Here's an example using NSURLConnection to send POST parameters:
// Note that the URL is the "action" URL parameter from the form.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL #"http://www.whereq.com:8079/answer.m"]];
[request setHTTPMethod:#"POST"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"content-type"];
//this is hard coded based on your suggested values, obviously you'd probably need to make this more dynamic based on your application's specific data to send
NSString *postString = #"paperid=6&q77=2&q80=blah";
NSData *data = [postString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
[request setValue:[NSString stringWithFormat:#"%u", [data length]] forHTTPHeaderField:#"Content-Length"];
[NSURLConnection connectionWithRequest:request delegate:self];
Im trying to send a data or what it seems to a form that is on the website, the action is freecontactformprocess.php and my code goes like this,
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"http://www.irabwah.com/freecontactformprocess.php"]];
[request setHTTPMethod:#"POST"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"content-type"];
NSString *postString = [NSString stringWithFormat:#"Full_Name=%#&Email_Address=%#&Telephone_Number=%#&Your_Message=%#&AntiSpam=25",_fNameLabel.text, _emailLabel.text,_phoneLabel.text, _commentText.text];
NSData *data = [postString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
[request setValue:[NSString stringWithFormat:#"%u", [data length]] forHTTPHeaderField:#"Content-Length"];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:request delegate:self];
if(conn){
NSLog("Successfull!!");
}
the purpose of this form is to send an email into my account which I integrated into the form on installation of this plugin, but the thing is I doesn't seems to get a the email when I run my test app, and when Im inputing values I don't include spaces yet.
The form looks like this,
hello i know this has been asked and answered many times but i cant seem to understand how it works (im new to iphone dev & objective c in general)
i am trying to make a create user for my app. i have a file create.php on my server that expects to get a _POST variable called id. after it is called it echos "DONE" for success and "EXIT" for failure.
i found some code and altered it (to the best of my knowledge) to fit my needs :
NSMutableString *tmpurl = [NSMutableString stringWithString: #"http://mysite.com/"];
[tmpurl appendString:#"create.php"];
NSURL *url = [NSURL URLWithString:tmpurl];
NSString *uid = #"32478907348920437829078902347804930893741"; // should chenge for randome.
NSString *post = [NSString stringWithFormat:#"id=%#", uid];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:postData];
now i don't know how to see what the page echos back or even if it has reached it.
any information would be appreciated and thank you in advance.
You are missing the NSURLConnection. Depending if you want to send this request synchronous or async, you may need to implement the NSURLConnectionDelegate methods.