我尝试将捕获的图像从 iPhone 保存到服务器。我完成了 Xcode。像这样的代码
NSMutableURLRequest *request= [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: attachment; name=\"%@\" filename=\"Test.png\"\r\n", imgName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:delegate];
现在我尝试使用单点触控,
在这里我创建连接,发送请求和接收响应工作正常。
但是这里我不知道如何将 Header & Body 设置为 NSMutableURLRequest,只是我需要知道如何传递参数(如上面的 Xcode)。
NSMutableUrlRequest request = new NSMutableUrlRequest(new NSUrl("http://url.com"), NSUrlRequestCachePolicy.ReloadRevalidatingCacheData, 20);
request.HttpMethod = "POST";
var connectionDelegate = new TestNSURLConnectionDelegate();
var connection = new NSUrlConnection(request, connectionDelegate);
connection.Start();
任何人都可以帮我解决这个问题...