objective c - post request to server does not send the content of textfields? -
i'm trying send content of textfields firstname , lastname button sendpost php server. once run app , fill textfields random text , press send, receive e-mail on server there no content.
(void) sendaction{ nserror *error = nil; nsstring *postparams = [nsstring stringwithformat:@"info=%@_%@",firstname.text,lastname.text]; nsdata * postdata = [postparams datausingencoding:nsasciistringencoding allowlossyconversion:yes]; nsstring * postlength= [nsstring stringwithformat:@"%d",[postdata length]]; nsmutableurlrequest *request = [[nsmutableurlrequest alloc]init]; [request seturl:[nsurl urlwithstring:@"http://faketest.com/test/mail.php"]]; [request sethttpmethod:@"post"]; [request setvalue:postlength forhttpheaderfield:@"content-length"]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"current-type"]; [request sethttpbody:postdata]; nsdata * rawdata = [nsurlconnection sendsynchronousrequest:request returningresponse:nil error:&error]; nsstring *rawdatastring =[[nsstring alloc]initwithdata:rawdata encoding:nsutf8stringencoding]; nslog(@"%@",rawdatastring); }
i believe may because you're using "current-type" header, instead of usual "content-type" header. try following , see if solves problem:
[request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"];
Comments
Post a Comment