作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
NSURL *url = [NSURL URLWithString:@"contact.php"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"companyID", constCompanyID,
nil];
NSURLRequest *request = [httpClient requestWithMethod: @"POST" path:@"contact.php" parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
for(id entry in JSON)
{
self.strAddr = [entry valueForKeyPath:@"addr"];
CCLOG(@"Address: %@", self.strAddr);
}
} failure:nil];
[operation start];
CCLOG(@"Address: %@", strAddr);
在日志中,地址为空。 PHP 很好;在浏览器中,它返回我想要的内容。
这段代码一直有效,直到我添加了 AFHTTPClient 以传入一个变量。我一定做错了什么,或者我不能那样做吗?
最佳答案
在第 1 行,您尝试从“contact.php”创建一个 URL(NSURL +URLWithString:
返回 nil
),但您确实需要这样做是基本 URL——在对特定 Web 服务的请求中常见的完整 URL,例如“http://api.twitter.com/1/”。
关于ios - AFJsonRequest 和 AFHttpClient 一起工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10054850/
NSURL *url = [NSURL URLWithString:@"contact.php"]; AFHTTPClient *httpClient = [[AFHTTPClient alloc]
我是一名优秀的程序员,十分优秀!