IOS 使用ASIHttpRequest 或 MKNetworkKit 上传图片到ASP.NET

上传图片和数据到服务器 是最基本的需求了,有些学IOS的 可能对服务器怎么接收图片这块不太了解。 所以今天 我把服务器的代码 也拷过来了。。。  只会ASP.NET 。。   PHP 和J2EE 应该差不多 都是几句话的事
 
IOS端代码:
 
NSString* path =  [[NSBundlemainBundle]pathForResource:@"iphone1-1-10"ofType:@"png"];
#pragma mark 使用ASIHttpRequest 上传图片和数据
   ASIFormDataRequest* request = [ASIFormDataRequestrequestWithURL:[NSURLURLWithString:@"http://192.168.0.1/IOSUPLOAD/default. aspx"]];
    [requestaddFile:pathforKey:@"img"];
    [requestaddPostValue:@"asihttp"forKey:@"name"];
    [request setCompletionBlock:^{
       NSLog(@"%@",request.responseString);
    }];
    [requestsetFailedBlock:^{
           NSLog(@"asi error: %@",request.error.debugDescription);
    }];
    [request startAsynchronous];
#pragma mark 使用MKNetworkKit 上传图片和数据
    MKNetworkEngine* engine = [[[MKNetworkEnginealloc]init]autorelease];
    NSDictionary* postvalues = [NSDictionarydictionaryWithObjectsAndKeys:@"mknetwork",@"name",nil];
    MKNetworkOperation* op = [engineoperationWithURLString:@"http://192.168.0.1/ IOSUPLOAD/default.aspx"params:postvalueshttpMethod:@"POST"];
    [opaddFile:pathforKey:@"img"];
    [opaddCompletionHandler:^(MKNetworkOperation *completedOperation) {
       NSLog(@"%@",request.responseString);
    }errorHandler:^(MKNetworkOperation *completedOperation,NSError *error) {
            NSLog(@"mknetwork error : %@",error.debugDescription);
    }];
    [engineenqueueOperation:op];
    //看上去就是跟示例的差不多
         
ASP.NET服务端的代码:
[csharp] www.2cto.com
protected void Page_Load(object sender, EventArgs e)  
{  
    if (Request.Files.Count == 0)  
    {  
        Response.Write("none file");  
    }  
    else  
    {  
        HttpPostedFile file = Request.Files["img"];  
        String filename = Request.Form["name"];  
        file.SaveAs(MapPath("~/"+filename+".png"));  
          
        Response.Write("ok");  
    }  
}  
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值