iPhone sending POST with NSURLConnection

后端 未结 5 1923
萌比男神i
萌比男神i 2020-11-27 14:27

I\'m having some problems with sending POST data to a PHP script with NSURLConnection. This is my code:

    const char *bytes = [[NSString stringWithFormat:@         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 15:13

    If you use NSURLSession then in iOS9 set

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    [request addValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"application/json" forHTTPHeaderField:@"Accept"];
    request.HTTPMethod = @"POST";
    

    In PHP set

    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password) 
      or die("Unable to connect to MySQL");
      echo "Connected to SQL.";
    
    //select a database to work with
    $selected = mysql_select_db($db,$dbhandle) 
      or die("Could not select anons db");
      echo "Connected to DB sucess.";
    
    mysql_query("SET NAMES 'utf8'"); 
    mysql_query("SET CHARACTER SET 'utf8'");
    mysql_query("SET SESSION collation_connection = 'utf8_general_ci'");
    

    In the db (MySql5) set utf-8_generic.

提交回复
热议问题