Sending Request and Get Response

前端 未结 3 570
广开言路
广开言路 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:48

    If you're looking for a way to make HTTP requests to a server, there's a number of frameworks that's helping you do that. Up until recently, ASIHTTPRequest was the one i favored, but unfortunately it's been discontinued.

    Google's API Client Library is also a good option, as well as a number of others suggested by the creator of ASIHTTPRequest.

    There should be plenty of docs in there to get you started.

    EDIT: To make your specific request with ASIHTTPRequest, do the following in a class with the protocol ASIHTTPRequestDelegate:

    /**
     * Make a request to the server.
     */
    - (void) makeRequest {
        // compile your URL string and make the request
        NSString *requestURL = [NSString stringWithFormat:@"%@?u=%@&  p=%@&platform=ios", url, txtUserName.text, txtPassword.text];
    
        NSURL *url = [NSURL URLWithString:requestURL];
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        [request setDelegate:self];
        [request startAsynchronous];
    }
    
    /**
     * Handle the response from the previous request.
     * @see ASIHTTPRequestDelegate
     */
    - (void) requestFinished:(ASIHTTPRequest*)request {
        NSString *responseString = [request responseString];
        // do whatever you need with the response, i.e. 
        // convert it to a JSON object using the json-framework (https://github.com/stig/json-framework/) 
    }
    

提交回复
热议问题