【发布时间】:2016-02-23 08:48:22
【问题描述】:
我已经查看了所有内容,并希望从 iPhone 应用程序中进行简单的字符串上传。我已经在线使用了所有代码。 iPhone 可以正常工作。它从 php 文件中检索代码并将其打印到控制台。但是php脚本中的值返回空。
<?php
$string = $_POST["string"];
if(strlen ($string)==0){
echo"empty";
}else{
echo "The string is: ". $string;
}
?>
这是 iOS 代码
- (void) sendCode{
// Create your request string with parameter name as defined in PHP file
NSString *myRequestString = [NSString stringWithFormat:@"string=%@&",signInCode.text];
// Create Data from request
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://artistfolio.net/signin.php"]];
// set Request Type
[request setHTTPMethod: @"POST"];
// Set content-type
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
// Set Request Body
[request setHTTPBody: myRequestData];
// Now send a request and get Response
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(conn)
{
NSLog(@"Good");
}
else
{
NSLog(@"Bad");
}
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
// Log Response
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",response);
}
【问题讨论】:
-
$code在哪里?HTML在哪里? -
在 iOS 中如何发送数据?
-
对不起@Mr.Engineer 我没有任何HTML代码