我正在制作需要与Sendy API进行通信的iPhone应用程序。我认为,它使用某种JSON,但我不太确定,也不知道从哪里开始。我对API的subscribe
部分特别感兴趣。 基本上,我需要知道如何从我的应用程序与Sendy API交谈。iOS将Sendy API集成到应用程序中
任何帮助表示赞赏。
我的代码:
- (IBAction)submitButtonPressed:(id)sender
{
self.data = [[NSMutableData alloc] initWithLength:0];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.erwaysoftware.com/sendy/subscribe"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"[email protected]" forHTTPHeaderField:@"email"];
[request setValue:@"john" forHTTPHeaderField:@"name"];
[request setValue:@"LxxxxxxxxxxxxxxxxxxxxQ" forHTTPHeaderField:@"list"];
[request setValue:@"true" forHTTPHeaderField:@"boolean"];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:request delegate:self];
[conn start];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[self.data setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d {
[self.data appendData:d];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", @"")
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil] show];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseText = [[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding];
// Do anything you want with it
NSLog(@"%@", responseText);
}
当日志发生,字符串为空。我通过断点知道最后一个方法被调用。
我仍然很难与它...我已经在问题中张贴我的代码。 – Undo 2013-04-04 21:28:37
如果我向代码中的URL发送POST请求,它会显示为空白。你确定服务设置正确吗? – 2013-04-04 21:40:11
我真的不知道...今天晚些时候我会做一些研究。 – Undo 2013-04-04 21:52:35