objective c - sending files to server and receiving feedback -
i have code send file server:
nsdata *data = [nsdata datawithcontentsoffile:path]; nsmutablestring *urlstring = [[nsmutablestring alloc] initwithformat:@"name=thefile&&filename=recording"]; [urlstring appendformat:@"%@", data]; nsdata *postdata = [urlstring datausingencoding:nsasciistringencoding allowlossyconversion:yes]; nsstring *postlength = [nsstring stringwithformat:@"%d", [postdata length]]; nsstring *baseurl = @"http://websitetester.com/here.php"; nsurl *url = [nsurl urlwithstring:baseurl]; nsmutableurlrequest *urlrequest = [nsmutableurlrequest requestwithurl:url]; [urlrequest sethttpmethod: @"post"]; [urlrequest setvalue:postlength forhttpheaderfield:@"content-length"]; [urlrequest setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; [urlrequest sethttpbody:postdata]; nsurlconnection *connection = [nsurlconnection connectionwithrequest:urlrequest delegate:self]; [connection start]; nslog(@"file send server!");
this code works receive return server, php file @ end of code show:
<?php if(...){ ... echo "data received"; }else{ ... echo "error in server"; } ?>
all i'm trying receive echo in php , show alert inside app, how code can implement inside code that?
edit
hey find code receive return data in objetive-c, code is:
nsurlresponse* response; nserror* error; nsdata* result = [nsurlconnection sendsynchronousrequest:urlrequest returningresponse:&response error:&error]; nsstring *returnstring = [[nsstring alloc] initwithdata:result encoding:nsutf8stringencoding]; nslog(@"return: %@",returnstring);
and code works way expected.
Comments
Post a Comment