0
我嘗試將捕獲的圖像從iPhone保存到服務器。我完成了Xcode。像在monotouch中使用NSMutableURLRequest調用webservice
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];
代碼現在我嘗試用MonoTouch的,
我在這裏創建連接,發送請求&接收響應工作正常。
但是在這裏我不知道如何設置標題& 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();
任何一個可以幫助我,這...
如果您使用Xarmain,最好的方法是使用標準的C#方法做一個Web服務調用(Web客戶端或HttpWebRequest的),就像您在任何其他.NET程序。 – Jason