将iphone代码转换为c#以上传文件 [英] Convert iphone code to c# to upload a file

查看:52
本文介绍了将iphone代码转换为c#以上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下iphone代码用于上传服务器中的文件。我想将它转换为c#,以便我可以在我的地铁应用程序中使用它。



Following iphone code is used to upload file in server. And I want to convert this to c# so that I can it use it in my metro application.

NSString *urlString = [NSString stringWithFormat:@"http://ip address/win8/PNGUpload-xml.php?device=win8&UID=%@",appDelegate.UID];


NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[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--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];


[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.png\"\r\n",appDelegate.UID] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];


[body appendData:imageData];

[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];


// now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(@"Returned: %@" ,returnString);

推荐答案

你不是需要转换任何内容...

请参阅:如何从互联网上下载文件 [ ^ ]。它应该适用于地铁应用。



BTW:谢谢谢谢谢谢你的出色工作!





下载和上传意味着几乎相同,但方向不同;)



从这里开始:QuickStart:正在上传文件 [ ^ ]

使用C#在Metro风格中上传捕获的图像 [ ^ ] < br $> b $ b

[/编辑]
You don''t need to convert anything...
See this: how to download a file from internet[^]. It should works with metro application.

BTW: Thank you Sergey for your Great Job!


Downloading and Uploading means almost the same but in different direction ;)

Start here: QuickStart: Uploading a file[^]
Upload Captured Image in Metro Style using C#[^]

[/EDIT]


这篇关于将iphone代码转换为c#以上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆