I'm writing this code for access webservice and getting an error (EXPECTED EXPRESSION)
-(IBAction)loginAction:(id)sender //here I m getting the error( (*expect expresion)))
{
NSString *urlStr = [NSString stringWithFormat:#"http://192.168.0.2/mobileBill/login.ashx?username=%#&password =%#&simno=%#", username.text, password.text, #""];
NSURL *url = [NSURL URLWithString:urlStr];
request = [NSMutableURLRequest requestWithURL:url];
connection = [NSURLConnection connectionWithRequest:request delegate:self];
}
Some other function before -(IBAction)loginAction:(id)sender may not be closed. Try adding } before this function. And check whether all the functions have the correct opening and closing braces.
Related
-(void)gettop10button
{
NSURL *url=[NSURL URLWithString:#"http://appabn.com/iphone/files/api/api.php?q=helo_users&u_id=5&page=1"]; // web api link
NSURLRequest *request=[NSURLRequest requestWithURL:url];
connection=[NSURLConnection connectionWithRequest:request delegate:self];
in the last of the link we see that page=1 , i have more than 10 pages .
so how can i pass a variable/parameter/argument , so i can increment page no.
Thanks in advance 'int page;
page++;
can perform like as .
in the last of the link we see that page=1 , i have more than 10 pages .
so how can i pass a variable/parameter/argument , so i can increment page no.
Thanks in advance 'int page;
page++;
can perform like as .
if(connection)
{
webData=[[NSMutableData alloc]init];
}
[JustConfesstable reloadData];
It's so simple. I am still amazed which part of the code you are not getting. You just have to take one variable (say pageNo) of type int and then provide it the default value 1.
You just have to increment the pageNo (using pageNo++) to get the next page value and then you have to create string for URL with pageNo and then simply pass it to URL using the method called URLWithString of class NSURL.
Translation of all the above description in 4 easy steps using Objective-C :
NSString *urlString = [NSString stringWithFormat:#"http://appabn.com/iphone/files/api/api.php?q=helo_users&u_id=5&page=%d",pageNo];
NSURL *url = [NSURL URLWithString:urlString]; // web api link
NSURLRequest *request = [NSURLRequest requestWithURL:url];
connection = [NSURLConnection connectionWithRequest:request delegate:self];
While running iphone app, several times i got the following Error
The connection failed due to a malformed URL
At CFNetwork Error Codes Reference, i got the info that this error triggered by CFNetwork
When and Why this error is triggered ?
How to get rid from this error?
NSURLConnection has a method canHandleRequest which will return a boolean whether the url is valid or not, e.g.
NSString *strUrl = [NSString stringWithFormat:#"http://test.com/stopBoard/%i",busStopCode];
NSURL *url = [NSURL URLWithString:strUrl];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:20.0];
// a cache policy of NO must be used otherwise the previous query is used if the phone is not online
BOOL canGo = [NSURLConnection canHandleRequest:request];
if(canGo){
connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self
startImmediately:YES];
} else {
self.errorMessage = #"\n\nurl check failed\n\n";
return NO;
}
i calling web service from my ios app using NSURLConnection. here is my code
#define kBaseServerUrl #"http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/"
#define kProductServiceUrl #"Products"
-(void)callService{
NSURL *url;
if (currState == ProductServiceState) {
url = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#/%d",kBaseServerUrl,kProductServiceUrl,[self getRevisionNumberForProduct]]];
}
else if(currState == TankStrickerServiceState){
url = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#/%d",kBaseServerUrl,kTankStrickerServiceUrl,[self getRevisionNumberForTankStricker]]];
}else if(currState == CalculationServiceState){
url = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#/%d",kBaseServerUrl,kCalculationServiceUrl,[self getRevisionNumberForCalculation]]];
}else{
//Future Use
}
NSLog(#"%#",[url absoluteString]);
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
NSLog(#"%#",urlConnection);
}
Its end up calling this url http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/Products/123
but when i hit this url in browser its working fine, but in my app i m getting this error
Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."
Please help me what might be problem
Looks like you are setting it up right, I would suspect something regarding your objects - try calling a hard coded URL by replacing your existing URL request with:
NSURLRequest *urlRequest = [NSURLRequest
requestWithURL:[NSURL URLWithString:#"http://www.google.com"]];
Should make troubleshooting this much easier.
i have this in Xcode:
NSString *post =[[NSString alloc] initWithString:#"message";
this string i want to send to myadress.php. anybody help me with some good reference or code please.
this is my php side:
<?
$connect = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
mysql_select_db("$dbname") or die(mysql_error());
$feed = $_GET['feed_message'];
$login = mysql_query("INSERT INTO feedback SET feed_message ='".$feed."'", $connect) or die(mysql_error());
mysql_close($connect);
?>
You can try this and you need implement the NSURLConnection delegate method
NSURL *url = [NSURL URLWithString:#"http://yoururl"];
NSURLRequest *urlReq = [NSURLRequest requestWithURL:url];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:urlReq delegate:self];
[connection start];
You can also use ASIHttpRequest, it has more Features.
In fact you just want to send a request to specific URL containing parameter "feed_message":
http://myserver.com/myscrypt.php?feed_message=message
To do it you need:
a. Create an url:
NSString * scriptURLString = #"http://myserver.com/myscrypt.php";
NSString * parameterName = #"feed_message";
NSString * post = #"message";
NSString * urlString = [NSString stringWithFormat:#"%#?%#=%#",scriptURLString, parameterName, post];
NSURL * url = [NSURL URLWithString:urlString];
b. send request to url. There are many ways to do it depending on your needs.
You may send asynchronous request (set delegate property and implement delegate methods to handle results)
[NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:url] delegate:nil];
or simply use NSData synchronous method:
[NSData dataWithContentsOfURL:url];
I am trying to send a query as part a the URL to obtain an XML file, and then trying to parse the XML file using NSXMLParser and initWithContentsOfURL. However the parser is not able to parse the file. I tested the parser with the same file, but this time the file was saved on the server (it was not being generated) and it worked just fine, so I know it is not a problem with the parser.
I have come to think that it does not parse it because I need to load the file before I try to parse it, or give the initWithContentsOfURL time to load the contents. So I tried to put those contents in a NSString and a NSData and using a sleep function as well as using a block but that did not work either.
What would be the best way to go about this problem?
Here is some of the code:
NSString *surl = [NSString stringWithFormat:#"http://lxsrv7.oru.edu/~maria_hernandez/query.xml"];
url = [NSURL URLWithString:surl];
NSString *curl = [[NSString alloc] initWithContentsOfURL:url];
NSLog(#"URL: %#", surl);
NSLog(#"URL Content: %#", curl);
SXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:receivedData];
//Other stuff we have tried:
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:surl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLResponse = nil;
NSError = nil;
receivedData = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &theResponse error: &error];
Let me know if you have more questions or if you wish to see more code.
Thanks!
have you tried setting a delegate for the NSXMLParse that implements the NSXMLParserDelegate which has events for parsing the document
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html