iPhone 网络服务 [英] iPhone Web Service

查看:35
本文介绍了iPhone 网络服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,我必须将用户的详细信息发送到服务器才能在应用程序中注册.我已经完成了 UI,但无法找到如何发送用户详细信息(例如姓名、电话号码、地址等)的解决方案.我需要有人从一开始就指导我完成整个过程.后端已经写好了,是用PHP写的.

I am working on a project where I have to send the details of the users to the server to register in the app. I am done with the UI but not able to find solution to how I can send the users details such as Name, Phone number, address and all. I would need someone to guide me through the process from the beginning. The back end is already written and it is in PHP.

推荐答案

100% 有效

NSString *post = [NSString stringWithFormat:@"username=%@&password=%@",@"Raja",@"12345"];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[post length]];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://localhost/promos/index.php"]];


[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];

NSURLConnection *theConnection = [NSURLConnection connectionWithRequest:request delegate:self];

if( theConnection ){
    // indicator.hidden = NO;
    mutableData = [[NSMutableData alloc]init];
}

您的 PHP 代码

<?php
    $username = $_POST['username'];
    $password=$_POST['password'];


    echo $username;
?>

这篇关于iPhone 网络服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆