【问题标题】:having trouble upload image from iphone Photo Picker to a server using ASIFormDataRequest使用 ASIFormDataRequest 将图像从 iphone Photo Picker 上传到服务器时遇到问题
【发布时间】:2010-06-28 16:40:08
【问题描述】:

基本上我正在尝试使用 ASIFormDataRequest 上传图像。这是我的以下代码

ASIFormDataRequest *request = [ASIHTTPRequest requestWithURL:urlImg];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"Content-Type" value:@"application/xml"];
[request setDelegate:self];

[request setTimeOutSeconds:500];  
NSData *imageData = UIImagePNGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"]);
[request setData:imageData forKey:@"media"];
[request startAsynchronous];

基本上我的应用程序会崩溃并给我以下错误:

[ASIHTTPRequest setData:forKey:]: unrecognized selector sent to instance 0x8880db0
2010-06-28 12:33:49.803 vdq[7658:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[ASIHTTPRequest setData:forKey:]: unrecognized selector sent to instance 0x8880db0'

不知道为什么,但是 setData 方法似乎在那个实例中。

【问题讨论】:

    标签: iphone objective-c upload asihttprequest


    【解决方案1】:

    几件事。你得到它的原因是因为第一行:

    ASIFormDataRequest *request = [ASIHTTPRequest requestWithURL:urlImg];
    

    正在创建 ASIHTTPRequest 类型的新对象。你需要做的:

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:urlImg];
    

    另外,您不需要设置 RequestMethod,因为这是自动完成的。最后,如果服务确实需要上传一个 XML 文档。然后您将无法使用 FormData。格式数据仅适用于您上传与 HTML 表单匹配并使用多部分表单或 url 编码数据编码的数据。如果需要 XML,您将需要自己构建 XML 文档,然后发布该文档中的数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      相关资源
      最近更新 更多