Ios 将图像从iPhone上传到服务器

Ios 将图像从iPhone上传到服务器,ios,iphone,objective-c,xcode,Ios,Iphone,Objective C,Xcode,**我在stackoverflow中查阅了很多关于将图像从iPhone上传到服务器的答案,但仍然没有找到解决方案 这是一个简单的图像上传,附带一个用户ID,下面是我的代码** NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ; request.timeoutInterval = 60; [request setURL:[NSURL URLWithString:url]]; [request setHTTPMe

**我在stackoverflow中查阅了很多关于将图像从iPhone上传到服务器的答案,但仍然没有找到解决方案

这是一个简单的图像上传,附带一个用户ID,下面是我的代码**

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;

request.timeoutInterval = 60;

[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"image/png" forHTTPHeaderField:@"Content-Type"];    
[request setValue:@"07ee7054-010b-44da-a14f-02e3e66800b7" forHTTPHeaderField:@"userId"];
[request imageData];

conn = [[NSURLConnection alloc]
        initWithRequest:request
        delegate:self startImmediately:NO];

[conn scheduleInRunLoop:[NSRunLoop mainRunLoop]
                forMode:NSDefaultRunLoopMode];
[conn start];

if (conn)
{
    receivedData = nil;
    receivedData = [NSMutableData data] ;
    [receivedData setLength:0];
}
这就是我的服务器端的外观

我得到的回应是


有人能帮我渡过难关吗?提前感谢。

您不能同时发送内容类型:图像/png和字符串数据。您需要发送一个请求。您需要设置您的服务器来处理此问题。

错误提示自我回答:@remes,感谢您清楚地编辑我的帖子。我把它告诉了我的服务器端,现在它似乎正在工作。谢谢
@RequestMapping(value = "/uploadphoto", method = RequestMethod.POST, headers="Accept = */*")
public Map<String,Object> uploadPhoto(InputStream in,@RequestBody String JSONContentofPOST)
{
    return UploadPhoto(in,JSONContentofPOST);
} 
<html>
   <head>
      <title>Apache Tomcat/7.0.53 - Error report</title>
      <style>
         <!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}-->
      </style>
   </head>
   <body>
      <h1>HTTP Status 400 - Required String parameter 'userId' is not present</h1>
      <HR size="1" noshade="noshade">
      <p><b>type</b> Status report</p>
      <p><b>message</b> <u>Required String parameter 'userId' is not present</u></p>
      <p><b>description</b> <u>The request sent by the client was syntactically incorrect.</u></p>