【发布时间】:2016-09-15 04:03:27
【问题描述】:
我正在尝试使用按钮从 IOS 应用程序向特定 URL 发出发布请求,并使用第二个按钮检索这些发布的参数。
这是我目前正在做的事情:
- (IBAction)firstButton:(id)sender {
NSString *id = @"12345";
NSDictionary* headers = @{@"accept": @"application/json"};
session = [NSString stringWithFormat:@"http://xyz.io/sessions/%@/", id];
NSDictionary* parameters = @{@"session_url": session};
[[UNIRest post:^(UNISimpleRequest *request) {
[request setUrl:[NSString stringWithFormat:@"%@devices/%@", BASE_URL, @"914-11e6-b775-02"]];
[request setHeaders:headers];
[request setParameters:parameters];
}] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) {
if (error) {
NSLog(@"post request submit error = %@", error);
return;
}
else
{
NSLog(@"post request success");
}
}
];}
获取参数的第二个按钮如下所示:
- (IBAction)secondButton:(id)sender{
NSString *deviceId = @"914-11e6-b775-02";
NSDictionary* headers = @{@"accept": @"application/json"};
[[UNIRest get:^(UNISimpleRequest *request) {
[request setUrl:[NSString stringWithFormat:@"%@devices/%@", BASE_URL, deviceId]];
[request setHeaders:headers];
}] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) {
// This is the asyncronous callback block
UNIJsonNode *body = response.body;
if (error) {
NSLog(@"error = %@", error);
return;
}
else
{
NSLog(@"session = %@", body.JSONObject[@"session_url"]);
}
}
];}
即使我从 firstButton 发布“session_url”对象,当我尝试从 secondButton 获取该对象时,它总是返回 (null)
我不知道为什么会这样,任何帮助将不胜感激。
附:在 firstButton 中,我在控制台日志中收到“发布请求成功”
【问题讨论】:
标签: ios objective-c iphone delegates http-post