我正在试着做一个简单的登录系统
我使用的是AFNetworking,这是我的登录函数:
- (void) login {
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:email.text, @"email", password.text, @"password", nil];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://localhost:8888"]];
[httpClient setParameterEncoding:AFFormURLParameterEncoding];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
path:@"http://localhost:8888/api.php"
parameters:params];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *response = [operation responseString];
NSLog(@"response: [%@]",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", [operation error]);
}];
[operation start];}
它返回状态400“错误的请求”,所以我假设我的帖子是错误的。但是我似乎找不到它有什么问题?
下面是登录APi的概览
function login() {
// Check for required params
if (isset($_POST['email']) && isset($_POST['password'])) {
// Put params into local variables
$email = $_POST['email'];
$pass = $_POST['password'];
echo 'Your email:' + $email + 'and password: ' + $password;
// look up params in db
$stmt = $this->db->prepare('SELECT `email`, `password`, `group_name` FROM `User` WHERE `email` = ? AND `password` = ?');
$stmt->bind_param('ss', $email, $password);
$stmt->execute();
$stmt->bind_result($u_email, $u_password, $group_name);
while ($stmt->fetch()) {
break;
}
$stmt->close();
// Bail if code doesn't exist
// Return unlock code, encoded with JSON
$result = array(
"group_name" => $group_name,
);
sendResponse(200, json_encode($result));
return true;
}
sendResponse(400, 'Invalid request');
return false;
} 如你所见,电子邮件/密码没有随帖子一起发送,因为它们的值没有设置。
这里的问题是什么?
发布于 2012-12-29 07:57:01
在运行web主机的计算机上获取wireshark。
http://www.wireshark.org/
然后,您可以读取服务器上传入的网络流量。
也许它甚至还没有到达服务器。或者可能端口8888被阻塞。
或者可能是http请求的格式不正确,服务器不知道该怎么做,因此它返回一个400
对于过滤器,您可以使用
tpc.port == 8888这样,它将只显示端口8888上的tcp流量
https://stackoverflow.com/questions/14076793
复制相似问题