首页 > 代码库 > origin connection, 语句对象,结果集,连接对象
origin connection, 语句对象,结果集,连接对象
//
// OriginNetwork.m
// guligei_AppFactory
//
// Created by wangyanan on 6/18/14.
// Copyright (c) 2014 wangyanan. All rights reserved.
//
#import "OriginNetwork.h"
@interface OriginNetwork()
@property(nonatomic,strong) NSURLConnection *connection;
@property(nonatomic,strong) NSMutableURLRequest *request;
@property(nonatomic,strong) NSURLResponse *response;
@end
@implementation OriginNetwork
-(IBAction)initwork:(id)sender
{
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"1239806145@qq.com",@"email",
@"111111",@"password",nil];
NSMutableData *data = http://www.mamicode.com/[[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:params forKey:@"AAA"];
[archiver finishEncoding];
NSString *getUserInfo=[NSString stringWithFormat:@"email=%@&password=%@",@"1239806145@qq.com",@"111111"];
NSData *dealPostData=http://www.mamicode.com/[getUserInfo dataUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:@"http://114.215.107.102/api/login"];
self.request = [NSMutableURLRequest requestWithURL:url];
[self.request setTimeoutInterval:60];
[self.request setHTTPMethod:@"POST"];
[self.request setHTTPBody:dealPostData];
NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
[self.request setValue:[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@", charset] forHTTPHeaderField:@"Content-Type"];
// [self.request setHTTPBody:data];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSDictionary *myDictionary = [unarchiver decodeObjectForKey:@"AAA"];
NSLog(@"%@",myDictionary);
[unarchiver finishDecoding];
self.connection = [[NSURLConnection alloc]initWithRequest:self.request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"%@",[response description]);
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",newStr);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
}
@end