Monday, 15 July 2013

ios - error while making URL request iPhone -



ios - error while making URL request iPhone -

i asked question , followed next way(suggested jaybit): pass username , password in url authentication

now, i'm getting error(stack track):

2013-02-12 11:56:11.734 calendar[4074:c07] didreceivedata 2013-02-12 11:56:19.519 calendar[4074:c07] receivedstring:<?xml version="1.0" encoding="utf-8"?><soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"><soap:body><soap:fault><soap:code><soap:value>soap:receiver</soap:value></soap:code><soap:reason><soap:text xml:lang="en">system.web.services.protocols.soapexception: server unable process request. ---&gt; system.xml.xmlexception: info @ root level invalid. line 1, position 1. @ system.xml.xmltextreaderimpl.throw(exception e) @ system.xml.xmltextreaderimpl.parserootlevelwhitespace() @ system.xml.xmltextreaderimpl.parsedocumentcontent() @ system.web.services.protocols.soapserverprotocol.soapenvelopereader.read() @ system.xml.xmlreader.movetocontent() @ system.web.services.protocols.soapserverprotocol.soapenvelopereader.movetocontent() @ system.web.services.protocols.soapserverprotocolhelper.getrequestelement() @ system.web.services.protocols.soap12serverprotocolhelper.routerequest() @ system.web.services.protocols.soapserverprotocol.initialize() @ system.web.services.protocols.serverprotocol.setcontext(type type, httpcontext context, httprequest request, httpresponse response) @ system.web.services.protocols.serverprotocolfactory.create(type type, httpcontext context, httprequest request, httpresponse response, boolean&amp; abortprocessing) --- end of inner exception stack trace ---</soap:text></soap:reason><soap:detail /> </soap:fault></soap:body></soap:envelope> (lldb)

here code:

- (ibaction)btnloginclick:(id)sender { //call calendar view if(self.viewcontroller == nil) { calendarviewcontroller *detailview = [[calendarviewcontroller alloc] initwithnibname:@"calendarviewcontroller" bundle:nil]; self.viewcontroller = detailview; } nsstring *username = [nsstring stringwithformat:@"parameteruser=%@",txtusername]; nsstring *password = [nsstring stringwithformat:@"parameterpass=%@",txtpassword]; nsurl *url = [nsurl urlwithstring:[nsstring stringwithformat:@"http://url/service1.asmx?"]]; nsstring *poststring = [nsstring stringwithformat:@"username=%@&password=%@",username, password]; nslog(@"%@",username); nslog(@"%@",password); nsdata *postdata = [nsdata datawithbytes: [poststring utf8string] length: [poststring length]]; //url requst object nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlrequestreloadignoringcachedata timeoutinterval:600]; [request sethttpmethod:@"post"]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; [request sethttpbody: postdata]; appconnection = [[nsurlconnection alloc] initwithrequest:request delegate:self]; [self.appconnection start];

//tryed async...

/* nsoperationqueue *queue = [[nsoperationqueue alloc] init]; [nsurlconnection sendasynchronousrequest:request queue:queue completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error) { nsstring *receivedstring = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding]; nslog(@"receivedstring:%@",receivedstring); }];*/ [self.navigationcontroller pushviewcontroller:self.viewcontroller animated:yes];

}

- (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { tempdata = data; nslog(@"didreceivedata"); if (!self.receiveddata){ self.receiveddata = [nsmutabledata data]; } [self.receiveddata appenddata:data]; } - (void)connectiondidfinishloading:(nsurlconnection *)connection { nslog(@"connectiondidfinishloading"); nsstring *receivedstring = [[nsstring alloc] initwithdata:tempdata encoding:nsutf8stringencoding]; nslog(@"receivedstring:%@",receivedstring);

}

please help.thank.

i've worked requesting soap url before, next code worked me:

nsstring *soapmessage = [nsstring stringwithformat: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<soap:envelope xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlns:xsd=\"http://www.w3.org/2001/xmlschema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" "<soap:body>\n" "<yourservicename xmlns=\"http://tempuri.org/\">\n" "<username>%@</username>\n" "<passowrd>%@</passowrd>\n" "</yourservicename>\n" "</soap:body>\n" "</soap:envelope>\n", username, password ]; nsurl *url = [nsurl urlwithstring:@"http://url/service1.asmx"]; nsmutableurlrequest *therequest = [nsmutableurlrequest requestwithurl:url]; nsstring *msglength = [nsstring stringwithformat:@"%d", [soapmessage length]]; [therequest addvalue: @"text/xml; charset=utf-8" forhttpheaderfield:@"content-type"]; [therequest addvalue: [nsstring stringwithformat:@"http://tempuri.org/%@",service] forhttpheaderfield:@"soapaction"]; [therequest addvalue: msglength forhttpheaderfield:@"content-length"]; [therequest sethttpmethod:@"post"]; [therequest sethttpbody: [soapmessage datausingencoding:nsutf8stringencoding]]; [therequest settimeoutinterval:10]; nsurlconnection *theconnection = [[nsurlconnection alloc] initwithrequest:therequest delegate:self]; if( theconnection ) { responsedata = [[nsmutabledata data] retain]; } else { nslog(@"theconnection null"); }

iphone ios objective-c url

No comments:

Post a Comment