你好朋友我在连接类中遇到问题我为我的不同方法使用相同的连接类。每个地方都可以正常工作,但是在建立这个特定连接时我得到错误,即:..连接确实失败并出现错误。
我正在发布我的整个代码,请帮助我。 发送我的网址并建立连接的代码:-
NSString *strURl=[NSString stringWithFormat:@"http://xxxyyy.com/API/index.php?action=listIt&login=%@&pwd=%@&name=%@&catID=%d&listID=&addr1=%@&addr2=%@&locName=&city=%@&state=%@&zip=&startDate=%@&startHours=%@&startMin=%@&startMeridiem=%@&endDate=%@&endHours=%@&endMin=%@&endMeridiem=%@&contactName=&contactPhone=&contactEmail=&contactWebsite=&cost=%d&description=%@",appDelegate.strUserName,appDelegate.strPassword,strTitle,self.subCat_ID,[txtAddress1.text urlEncodeUsingEncoding:NSUTF8StringEncoding],[txtAdress2.text urlEncodeUsingEncoding:NSUTF8StringEncoding],lblCity.text,lblState.text,strBeginDate,startHr,startMin,startMeridiem,strEndDate,strEndHr,strEndMin,strEndMeridiem,cost,[txtdDscription.text urlEncodeUsingEncoding:NSUTF8StringEncoding]];
//strURl=[strURl urlEncodeUsingEncoding:NSUTF8StringEncoding];
// NSString *strEncode=[strURl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// strEncode=[strEncode stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSLog(@" strListItURl =%@",strURl);
ConnectionClass *connection=[[ConnectionClass alloc]init];
[connection getResponseData:strURl];
connection.delegate=self;
[connection release];
NSLog(@"strListItURl =%@",strURl); 这是我发送的带有方法和参数的 url。 strListItURl http://xxxyyy.com/API/index.php?action=listIt&login=sawanth&pwd=sawanth&name=Hello One&catID=4&listID=&addr1=One%20tow&addr2=next%20one&locName=&city=Anchorage&state=阿拉斯加&zip=&startDate=11/8/ 2012&startHours=11&startMin=33&startMeridiem=上午&endDate=11/10/2012&endHours=11&endMin=33&endMeridiem=上午&contactName=&contactPhone=&contactEmail=&contactWebsite=&cost=3&description=%20Hello
注意:-当我直接在浏览器上粘贴“strListItURl”时,我得到了成功。
现在建立连接后,我进入连接类
-(void)getResponseData:(NSString*)strURL
{
NSLog(@"strURL =%@",strURL);
// NSString *str1 = [NSString stringWithFormat:@"%@",strURL];
NSURL *url=[NSURL URLWithString:strURL];
NSLog(@"url is =%@",strURL);
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
//Initialize the connection for NSURL Connection
theConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES];
if(theConnection)
{
//Initialize the data and retain the data
receiveData = [[NSMutableData data] retain];
}
else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Warning" message:@"Please check internet connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
在这里,当我打印 urlRequest 时,我发现 打印 urlRequest 的描述:NSURLRequest (null)
最后控制转到 -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
请告诉我我在哪里做错了:)