dongmei9961 2011-03-13 14:15
浏览 52
已采纳

iPhone到PHP到iPhone

I am trying to create a login system on an iPhone app but am coming across a bit of a problem. I believe that the code I have is sending the the NSString to the php but it is not echoing back the string like I want it to. What am I doing wrong?

I know the php code isn't doing much right now I just want to see that it is storing the values that I send it.

Thanks!

XCode:

    NSString *content = @"myusername=a&mypassword=s";

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://mywebsite.php"]];
    urlRequest = [[[NSMutableURLRequest alloc] init] autorelease];
    [urlRequest setHTTPMethod:@"POST"];
    [urlRequest setHTTPBody:[content dataUsingEncoding:NSISOLatin1StringEncoding]];


    // generates an autoreleased NSURLConnection
    [NSURLConnection connectionWithRequest:request delegate:self];

    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    NSLog(returnString);

}

PHP:

echo "first ". $_POST['myusename']." return";  
echo "second ". $_POST['mypassword']." return";
  • 写回答

2条回答 默认 最新

  • dongmubi4444 2011-03-13 14:27
    关注

    You allocate 2 NSMutableURLRequest objects. I'll try to correct your mistake:

    NSString *content = @"myusername=a&mypassword=s";
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://mywebsite.php"]];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[content dataUsingEncoding:NSISOLatin1StringEncoding]];
    ...
    

    Furthermore the string encodings do not match, that could cause problems.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题