Sending POST data from iphone over SSL HTTPS

前端 未结 4 1236
予麋鹿
予麋鹿 2020-11-30 17:13

Hai all,

In my iphone project i need to pass the user name and password to a web server,previously i pass data using GET method and used the url with GET format (eg:

4条回答
  •  渐次进展
    2020-11-30 17:55

    Well, this exactly is not an answer to your question. But as an alternative, have a look at this code.I use this successfully for sending username and password to server.

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:loginURL]];
    
    //set HTTP Method
    [request setHTTPMethod:@"POST"];
    
    //Implement request_body for send request here username and password set into the body.
    NSString *request_body = [NSString stringWithFormat:@"Username=%@&Password=%@",[Username stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [Password stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    //set request body into HTTPBody.
    [request setHTTPBody:[request_body dataUsingEncoding:NSUTF8StringEncoding]];
    
    //set request url to the NSURLConnection
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    
    
    if(theConnection) //get the response and retain it
    

    You can then implement the following delegate to check the response

    -(void)connectionDidFinishLoading:(NSURLConnection *)connection
    

    Hope this helps.

提交回复
热议问题