Sending Request and Get Response

前端 未结 3 615
广开言路
广开言路 2021-01-07 14:01

I have a php code running on my server that i call my web service.It processes the data in send integer value.How can i get that?Here is my request url :

  N         


        
3条回答
  •  死守一世寂寞
    2021-01-07 14:33

    You can use NSURLConnection. You should use implement the NSURLConnectionDataDelegate protocol and use the NSURLConnection class.

    -(void) requestPage
    {
        NSString *urlString = @"http://the.page.you.want.com";
        NSURL *url = [NSURL URLWithString:urlString];
    
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:20.0f];
    
    
        responseData = [[NSMutableData alloc] init];
        connection = [[NSURLConnection connectionWithRequest:request delegate:self] retain];
        delegate = target;
    }
    
    
    -(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {   
        if ([response isKindOfClass:[NSHTTPURLResponse class]])
        {
            NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response; 
            //If you need the response, you can use it here
        }
    }
    
    -(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
        [responseData appendData:data];
    }
    
    -(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {
        [responseData release];
        [connection release];
    }
    
    -(void) connectionDidFinishLoading:(NSURLConnection *)connection
    {
        if (connection == adCheckConnection)
        {
            NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    
            //You've got all the data now
            //Do something with your response string
    
    
            [responseString release];
        }
    
        [responseData release];
        [connection release];
    }
    

提交回复
热议问题