在IOS上发送HTTP POST请求
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",dk.baseURL,@"daantest"]]]; [request setHTTPMethod:@"POST"]; [request setValue:@"text/xml" forHTTPHeaderField:@"Content-type"]; NSString *sendString = @"<data><item>Item 1</item><item>Item 2</item></data>"; [request setValue:[NSString stringWithFormat:@"%d", [sendString length]] forHTTPHeaderField:@"Content-length"]; [request setHTTPBody:[sendString dataUsingEncoding:NSUTF8StringEncoding]]; PushDelegate *pushd = [[PushDelegate alloc] init]; pd = pushd; urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:pd]; [urlConnection start];
#import "PushDelegate.h"@implementation PushDelegate@synthesize data;-(id) init{ if(self = [super init]) { data = [[NSMutableData alloc]init]; [data setLength:0]; } return self;}- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten: (long long)totalBytesWritten{ NSLog(@"didwriteData push");}- (void)connectionDidResumeDownloading:(NSURLConnection *)connection totalBytesWritten:(long long) totalBytesWritten expectedTotalBytes:(long long)expectedTotalBytes{ NSLog(@"connectionDidResumeDownloading push");}- (void)connectionDidFinishDownloading:(NSURLConnection *)connection destination URL:(NSURL *)destinationURL{ NSLog(@"didfinish push @push %@",data);}- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWri tten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{
胡子哥哥