PHP POST脚本可用于其他站点,但不能用于iOS NSURLConnection
我已经尽了最大的努力去解决它,但是我找不到问题。这是密码 iOS: PHP:PHP POST脚本可用于其他站点,但不能用于iOS NSURLConnection,php,ios,post,nsurlconnection,Php,Ios,Post,Nsurlconnection,我已经尽了最大的努力去解决它,但是我找不到问题。这是密码 iOS: PHP: 这将返回以下内容: Username: <br>Password: 用户名:密码: 几个小时来我一直在想它到底出了什么问题。任何帮助都将不胜感激。这对我来说很好: @interface Test : NSObject -(void)userLogin; @end int main(int argc, const char * argv[]) { @autoreleasepool {
这将返回以下内容:
Username: <br>Password:
用户名:
密码:
几个小时来我一直在想它到底出了什么问题。任何帮助都将不胜感激。这对我来说很好:
@interface Test : NSObject
-(void)userLogin;
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Test *test = [[Test alloc] init];
[test userLogin];
}
return 0;
}
@implementation Test : NSObject
-(void)userLogin {
NSString *user = @"test";
NSString *pass = @"pass";
NSString *post = [NSString stringWithFormat: @"user=%@&pass=%@", user, pass];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:@"www.example.com/login.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
sleep(50);
NSLog(@"%@", conn);
}
@end
PHP:
检查Charles Proxy实际发送和接收的内容。谢谢,但它不起作用。PHP脚本只返回:
Array
我的脚本还是你的脚本?我在上面发布的内容正好返回了我粘贴的内容--您运行了吗?
Username: <br>Password:
@interface Test : NSObject
-(void)userLogin;
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Test *test = [[Test alloc] init];
[test userLogin];
}
return 0;
}
@implementation Test : NSObject
-(void)userLogin {
NSString *user = @"test";
NSString *pass = @"pass";
NSString *post = [NSString stringWithFormat: @"user=%@&pass=%@", user, pass];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:@"www.example.com/login.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
sleep(50);
NSLog(@"%@", conn);
}
@end
<?php
file_put_contents('/tmp/test', print_r($_POST, true));
# cat /tmp/test
Array
(
[user] => test
[pass] => pass
)