1

我实现了一个向服务器发送注释的方法:

-(IBAction)inserttotextfied:(id)sender{

    NSString *strurl=[NSString stringWithFormat:@"http://localhost/get-data/insert.php?Name=%@&message=%@",txtf.text,txt2.text];
    NSData *dataurl=[NSData dataWithContentsOfURL:[NSURL URLWithString:strurl]];
    NSString *stresult=[[[NSString alloc]initWithData:dataurl encoding:NSUTF8StringEncoding]autorelease];
    NSLog(@"%a",stresult);
}

问题是当我通过模拟器测试它时正在发送,但是当我在设备中测试它时,数据没有被保存

4

3 回答 3

0

格式说明符%a64-bit floating-point number (double), printed in scientific notation with a leading 0x and one hexadecimal digit before the decimal point using a lowercase p to introduce the exponent.

如果这不是你的意图,试试这个:

NSLog(@"%@", stresult);
于 2012-07-18T07:20:49.893 回答
0

模拟器响应速度更快。所以url返回数据并正确打印。但在设备上,响应时间比模拟器高。你的 NSLog(@"%a",stresult); 语句在从响应中获取任何数据之前正在执行。我会建议给一些延迟或使用委托,以便您在得到响应后可以使用数据。

于 2012-07-18T06:36:54.983 回答
0

您可能不想在您的设备上向 localhost 发送内容,或者您​​是否在设备构建中使用了不同的 url?

于 2012-07-18T06:15:03.077 回答