我正在製作需要與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