ios - send Post request to PHP Server -


i tried send data 2 textfields button, once press button receive e-mail without content of textfields typed in ios simulator. can not find problem, please me.

viewcontroller.h

#import <uikit/uikit.h>  @interface viewcontroller : uiviewcontroller {     uitextfield * firstname;     uitextfield *lastname;     uibutton *sendpost; } @property (strong, nonatomic) iboutlet uitextfield *firstname; @property (strong, nonatomic) iboutlet uitextfield *lastname; @property (strong, nonatomic) iboutlet uibutton *postbuttontapped;   -(ibaction)postbuttontapped:(id)sender;   @end 

viewcontroller.m

#import "viewcontroller.h"  @interface viewcontroller ()  @end  @implementation viewcontroller @synthesize firstname; @synthesize lastname;  - (void)viewdidload {     [super viewdidload]; }  - (ibaction)postbuttontapped:(id)sender {     nsstring *myrequeststring = [nsstring stringwithformat:@"firstname=%@&lastname=%@",firstname.text,lastname.text];     nsdata *myrequestdata = [nsdata datawithbytes: [myrequeststring utf8string] length: [myrequeststring length]];      nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl: [nsurl urlwithstring: @"http://textfake.com/test/mail.php"]];      [request sethttpmethod: @"post"];     [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"];     [request sethttpbody: myrequestdata];      nsdata *returndata = [nsurlconnection sendsynchronousrequest: request returningresponse: nil error: nil];     nsstring *response = [[nsstring alloc] initwithbytes:[returndata bytes] length:[returndata length] encoding:nsutf8stringencoding];      nslog(@"%@",response); }  - (void) touchesbegan:(nsset *)touches withevent:(uievent *)event {     [self.firstname resignfirstresponder];     [self.lastname resignfirstresponder]; }  - (void)didreceivememorywarning {     [super didreceivememorywarning]; } 

php code

<?php header("content-type: text/html; charset=utf-8"); $firstname = $_post["firstname"]; $lastname = $_post["lastname"]; $text = "not set"; if(!empty($_post["text"])){     $text = $_post["text"]; } $lat = $_post["lat"]; $lon = $_post["lon"]; $diemessage =$firstname." ".$lastname."\n".$text."\n"; $diemessage .="lat:".$lat."\n"; $diemessage .="lon:".$lon; mail("fortesing@gmail.com", "gps daten", $diemessage); //echo 'email abgeschickt!'; echo $diemessage; ?> 

afnetworking 2.0

- (ibaction)postbuttontapped:(id)sender {     afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager];     nsdictionary *params = @{@"firstname": firstname.text,                              @"lastname": lastname.text};     [manager post:@"http://textfake.com/test/mail.php" parameters:params success:^(afhttprequestoperation *operation, id responseobject) {         nslog(@"json: %@", responseobject);     } failure:^(afhttprequestoperation *operation, nserror *error) {         nslog(@"error: %@", error);     }]; } 

hope works.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -