title: Upload image into asp.net web service in swift
body: <p>How can I upload an image into my web service then I can save it on my server!</p>
  
  <p>I have tried the below code using POST method but I got this error</p>
  
  <pre class="lang-none prettyprint-override"><code>(A potentially dangerous Request.Form value was detected from the client (uploadFile="&lt;ffd8ffe0 00104a46 4...").)
  </code></pre>
  
  <pre class="lang-swift prettyprint-override"><code>func myImageUploadRequest() {
      let imageData = UIImageJPEGRepresentation(myImageView, 1)
      let boundary = generateBoundaryString()
      var base64String = imageData.base64EncodedStringWithOptions(.allZeros)
  
      let myUrl = NSURL(string: "http://xxxxx/UploadImageTest");
          let request = NSMutableURLRequest(URL:myUrl!);
          request.HTTPMethod = "POST";
      request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
  
  
      if(imageData==nil) { return; }
      var body = NSMutableData();
      body.appendString("uploadFile=\(imageData)")
      request.HTTPBody = body
      let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
          data, response, error in
  
          if error != nil {
              println("error=\(error)")
              return
          }
  
          // You can print out response object
          println("******* response = \(response)")
  
          // Print out reponse body
          let responseString = NSString(data: data, encoding: NSUTF8StringEncoding)
          println("****** response data = \(responseString!)")
  
          dispatch_async(dispatch_get_main_queue(),{
          });
  
      }
  
      task.resume()
  }
  </code></pre>
  
  <p>And this the POST SOAP on my Asp.net web service</p>
  
  <pre class="lang-none prettyprint-override"><code>    POST /xxxx.asmx/UploadImageTest HTTP/1.1
      Host: xxxx.com
  Content-Type: application/x-www-form-urlencoded Content-Length: length
  
  uploadFile=string&amp;uploadFile=string
  </code></pre>