Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bobisa

macrumors newbie
Original poster
Nov 8, 2010
11
0
i had made a kind of html webservice

i want to be able to call by providing a parameters for example this page
http://mysite/pStatus.php?P1=myparam

this page will generate a page with no html balise, it will juste generate three answer

it can be

-1
0
1

and can i retrieve the source of a html request
 
yes, my question is how i retrieve the source of a webpage into a string ?
 
yes, my question is how i retrieve the source of a webpage into a string ?
You have at least two options:

1) If a synchronous (blocking) approach is desired (not recommended, though), you could simply use one of the instance methods of NSString that returns a string by reading data from a given URL.

2) If an asynchronous (non-blocking) approach is desired, you could look into using NSURLConnection as described in the URL Loading System Programming Guide.
 
if i follow this example, the result will be in the receivedData variable

if yes, what kind of variable it will be a string ?? and where do i have to declare it ??


Code:
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mywebsite.com/"]
                        cachePolicy:NSURLRequestUseProtocolCachePolicy
                    timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
    // Create the NSMutableData to hold the received data.
    // receivedData is an instance variable declared elsewhere.
    receivedData = [[NSMutableData data] retain];
} else {
    // Inform the user that the connection failed.
 
Last edited by a moderator:
if yes, what kind of variable it will be a string ?? and where do i have to declare it ??
It will be an NSMutableData. You will still need to convert it to an NSString. Since the comments allude to it being an instance variable, you should declare it where you normally declare instance variables.

P.S. Just be aware that the code you've supplied will not be enough to handle the entire task. There is still the delegate methods needed.
 
do you mean
- (void)connectionDidFinishLoading,....
and so on ?
 
do you mean
- (void)connectionDidFinishLoading,....
and so on ?
Based on this quote from the URL Loading System Programming Guide:
In order to download the contents of a URL, an application needs to provide a delegate object that, at a minimum, implements the following delegate methods: connection:didReceiveResponse:, connection:didReceiveData:, connection:didFailWithError: and connectionDidFinishLoading:.
what do you think? :)
 
i know it sound like i dont know what i do , but its the first time that i am coding something like that on a mac

habitually i am doing windows coding :)

that why
 
i know it sound like i dont know what i do , but its the first time that i am coding something like that on a mac

habitually i am doing windows coding :)

that why
Make sure you are comfortable with the fundamentals of Objective-C / Cocoa Touch coding before tackling the real issues. If not, no harm in stepping back and taking time to get to that comfort level.
 
i did some c++ at school.

it look familiar but i have to get rid of what i am doing in windows coding :)

when i click on my button , i got kicked out of the software on the iphone simulator

how can i find what is doing that

here is my code


Code:
- (IBAction)buttonClicked:(id)sender {
	// Create the request.
	webData = [[NSMutableData data] retain];
	NSLog("Before request");
	NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://html_webservice.gcilogistic.com/pParsCheckup.awp?P1=a"]];
	[[NSURLConnection alloc] initWithRequest:request delegate:self];
	NSLog("after request");
}


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
	NSLog("Void didreceiveresponse");
	[webData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
	NSLog("Void didreceiverdata");
	[webData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
	NSLog("connection failed");
	//label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
	NSLog("connectionfinishloading");
	[connection release];
}
 
Last edited by a moderator:
when i click on my button , i got kicked out of the software on the iphone simulator

how can i find what is doing that
Time to apply some basic debugging. Looks like you already have a number of NSLogs in your code. Which ones are you seeing in the console? Are you seeing anything else? Run-time errors, perhaps? And did your code build without any compile-time errors or warnings? If not, address those first. Etc.
 
i am not able to see the NSLog("Before request");

i got the following in the console

Program received signal : "EXC_BAD_ACCESS"

found my error
missing @ in the nslog function
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.